Sessions: remote control with less work
Close all open sessions in your shell.
Get-PSSession | Remove-PSSession
Establish a session to a remote computer. Save the session in a variable named $session.
$session = New-PSSession - ComputerName winserver
Use the $session variable to establish a one-to-one remote shell session with the remote computer. Display a list of processes and then exit.
Enter-PSSession - Session $session
Use the $session variable with Invoke-Command to get a list of services from the remote computer.
Invoke-Command - ScriptBlock {Get-Service } - Session $session
Use Get-PSSession and Invoke-Command to get a list of the 20 most recent Security event log entries from the remote computer.
Invoke-Command - ScriptBlock {Get-EventLog - Newest 20 - LogName Security} - Session (Get-PSSession )
Use Invoke-Command and your $session variable to load the ServerManager module on the remote computer.
Invoke-Command - ScriptBlock {Import-Module ServerManager} - Session $session
Import the ServerManager module’s commands from the remote computer to your computer. Add the prefix rem to the imported commands’ nouns.
Import-PSSession - Session $session - Module ServerManager - Prefix rem
Run the imported Get-WindowsFeature command.
Close the session that’s in your $session variable.
Remove-PSSession $session