WinRM and Enter-PSSession

WinRM and Enter-PSSession in PowerShell: PowerShell Remoting allows you to run commands on external servers over encrypted channels via the WS-Management…

PowerShell Remoting allows you to run commands on external servers over encrypted channels via the WS-Management protocol (WinRM) or SSH.

Interactive Sessions

Like SSH in Linux, you can drop your terminal shell directly into a remote server.

# Open an interactive shell into the database server
Enter-PSSession -ComputerName "SRV-DB-01" -Credential (Get-Credential)

# Terminal prompt changes. You are now controlling SRV-DB-01.
[SRV-DB-01]: PS C:\> Get-Service SQLBrowser
[SRV-DB-01]: PS C:\> Exit-PSSession

One-to-Many Execution (Invoke-Command)

The most powerful command in PowerShell administration stringing hundreds of computers simultaneously in parallel.

$domainServers = @("DC-01", "APP-01", "DB-01")

# Sends the script block 'Restart-Service spooler' to all 3 servers in parallel!
Invoke-Command -ComputerName $domainServers -ScriptBlock {
    Restart-Service -Name "Spooler" -Force
    Write-Output "Spooler reset verified on $env:COMPUTERNAME"
}