How to do it...

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:

  1. To create a session to a remote Windows machine, run the following command:
PS> $Session= New-PSSession -HostName wintel01 -UserName ramram@wintel01's password:
  1. To display the session details, call the $Session variable on the PowerShell console:
PS> $session
  1. To enter the remoting session, use the session parameter, along with the Enter-PSSession cmdlet:
PS> Enter-PSSession -Session $session[wintel01]: PS>
  1. To invoke the script on a remote machine, run the Invoke-Command cmdlet:
PS> Invoke-Command $session -ScriptBlock ...

Get PowerShell Core for Linux Administrators Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.