The New-PSSession, Enter-PSSession, and Invoke-Command cmdlets are the three cmdlets that help with the PowerShell remoting feature. Let's dig further to dissect the internals of PowerShell remoting:
- To create a session to a remote Windows machine, run the following command:
PS> $Session= New-PSSession -HostName wintel01 -UserName ramram@wintel01's password:
- To display the session details, call the $Session variable on the PowerShell console:
PS> $session
- To enter the remoting session, use the session parameter, along with the Enter-PSSession cmdlet:
PS> Enter-PSSession -Session $session[wintel01]: PS>
- To invoke the script on a remote machine, run the Invoke-Command cmdlet:
PS> Invoke-Command $session -ScriptBlock ...