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