Skip to content

Latest commit

 

History

History
60 lines (51 loc) · 1.6 KB

File metadata and controls

60 lines (51 loc) · 1.6 KB

Sessions: remote control with less work

  1. Close all open sessions in your shell.
Get-PSSession | Remove-PSSession

  1. Establish a session to a remote computer. Save the session in a variable named $session.
$session = New-PSSession -ComputerName winserver

  1. 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
Get-Process
Exit-PSSession

  1. Use the $session variable with Invoke-Command to get a list of services from the remote computer.
Invoke-Command -ScriptBlock {Get-Service} -Session $session

  1. 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)

  1. Use Invoke-Command and your $session variable to load the ServerManager module on the remote computer.
Invoke-Command -ScriptBlock {Import-Module ServerManager} -Session $session

  1. 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

  1. Run the imported Get-WindowsFeature command.
Get-remWindowsFeature

  1. Close the session that’s in your $session variable.
Remove-PSSession $session