Remoting Power in PowerShell

One of the many benefits of PowerShell 3.0 is its remoting ability. By remoting, I’m referring to the ability to run PowerShell commands from a single console and direct those commands to be executed on one or more remote computers. There are two ways to implement PowerShell remoting: single command execution and remote session.

Single Command Execution

Single command execution is where a single PowerShell commandlet is redirected to one or more computers using the Invoke-Command commandlet.  This commandlet has two parameters: -ComputerName whose values are a comma-separated list of computers that will received the command and the –ScriptBlock {} which contains the PowerShell commandlet to be executed.

Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME

Remote Session

The second method involves establishing a remote session with a single computer. The Enter-PSSession commandlet has two parameters: -ComputerName which is the name of the remote computer that will execute the commands within the session and –Credential which is the user account that has the rights to login to the remote computer.

Enter-PSSession -ComputerName COMPUTER -Credential USER

Once the session is established, simply enter the desired PowerShell commandlets to be run on the remote computer. When finished, use the Exit-PSSession commandlet to close the active remoting session.

For more information on PowerShell remoting, check out these links: