Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Run a PowerShell Command on Multiple Servers at the Same Time

$
0
0

Summary:  Run a Windows PowerShell cmdlet on multiple servers at the same time.

Hey, Scripting Guy! Question How can I run a Windows PowerShell cmdlet on multiple servers at the same time?

              Hey, Scripting Guy! Answer 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}

 


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>