Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

April 2010-intro-to-remoting-part2


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

April 2010-intro-to-remoting-part2

  1. 1. Introduction to PowerShell Remoting, Part 2<br />Matt Johnson, GSEC, MCSE<br /><br />
  2. 2. What are we going to cover?<br />Remote Commands<br />Reusable Sessions with PS Remoting<br />Interactive Sessions with PS Remoting<br />Temporary Sessions with PS Remoting<br />
  3. 3. Remote Commands<br />New-PSSession<br />Get-PSSession<br />Enter-PSSession<br />Exit-PSSession<br />Remove-PSSession<br />Invoke-Command<br />
  4. 4. PS Remoting Help<br />Get-Help <br />about_Remoting<br />about_PSSessions<br />about_Remote_Requirements<br />about_Remote_FAQ<br />about_Remote_Troubleshooting<br />
  5. 5. Reusable Sessions with PS Remoting<br />It is really easy to create a new PS Session<br />$dc = New-PSSession –computerName DC1<br />It is also really easy to enter that session<br />Enter-PSSession –Session $dc<br />More about that later!<br />
  6. 6. Reusable Sessions with PS Remoting Cont..<br />Less network / CPU cycles used when using Reusable sessions compared to running individual commands.<br />You can run one off commands if you are using Reusable sessions<br />Use Reusable sessions when you need to run more than one command against a computer.<br />
  7. 7. Demo<br />
  8. 8. Running Commands against muliple machines<br />$sessions = New-PSSession pc1, pc2, pc3<br />Invoke-Command { Md HKLM:Softwaremwjcomputing } –Session $sessions<br />
  9. 9. Passing Variables to Remote Hosts<br />You can pass variables to the Invoke-Command cmdlet<br />Your script block must use the param statement<br />Use the –ArgumentList switch<br />
  10. 10. Demo<br />
  11. 11. Interactive Sessions<br />Run at a console just like you are sitting there at the machine. <br />Run all normal PowerShell commands<br />You can restrict the commands that can be run remotely. <br />
  12. 12. Demo<br />
  13. 13. Code to change what is allowed to run<br /># Disable access to all applications<br />$ExecutionContext.SessionState.Applications.Clear()<br /># Disable access to scripts<br />$ExecutionContext.SessionState.Scripts.Clear()<br /># Define a list of allowed commands<br />$RequiredCommands = "Exit-PSSession", "Get-Command", "Get-FormatData", "Get-Help", "Measure-Object", "Out-Default", "Select-Object"<br />$Commands = $RequiredCommands + "Get-Process", "Get-Service", "Where-Object", "ForEach-Object"<br /># Make everything except the allowed commands private (not visible)<br />Get-Command | Where-Object {$Commands -notcontains $_.Name} | ForEach-Object {$_.Visibility="Private"}<br /># Restrict the language elements to a very limited set. The possible values are FullLanguage,RestrictedLanguage, and NoLanguage<br />$ExecutionContext.SessionState.LanguageMode="RestrictedLanguage"<br />
  14. 14. Code to change what is allowed to run cont.<br />Save as:<br />%windir%system32WindowsPowerShellv1.0 estricted.ps1<br />
  15. 15. Running single commands<br />Use Invoke-Command<br />Results are returned as text, not as objects<br />Adds some overhead by doing it this way<br />
  16. 16. DEMo<br />
  17. 17. Remoting Resources<br />Two very useful resources!<br />Get-Help<br />’s Administrators Guide to PowerShell Remoting<br />
  18. 18. Contact<br />Matt Johnson<br />Phone: +1 (734) 931-0323<br />Web:<br />Blog:<br />Twitter:<br />Email:<br />
  19. 19. Thanks!<br />