Summary: Run a Windows PowerShell cmdlet on multiple servers at the same time.
How can I run a Windows PowerShell cmdlet on multiple servers at the same time?
To run a Windows PowerShell cmdlet on multiple servers at the same time use the New-PSSession cmdlet and save the returned session object in a variable. Now use the Invoke-Command cmdlet with the session object to run the command. Use the ScriptBlock parameter to specify the cmdlet to run.
$session = New-PSSession -cn dc2,dc3 -cred iammred\administrator
Invoke-Command -Session $session -ScriptBlock {get-date}
0 comments