We help IT Professionals succeed at work.
Get Started

powershell - How to speed up script on multiple servers

String :-)
String :-) asked
on
59 Views
Last Modified: 2020-02-23
Much of my work involves runnning scripts against multiple servers. This morning for example I had to reset IIS on 48 servers:
 
Whilst this script works just fine, it is quite slow because it waits for each server in the list to complete the task before moving on to the next one.

foreach ($server in (Get-Content "D:\Deployment\_ServerLists\AppServers.txt")){

Invoke-Command -cn $Server -ScriptBlock { iisreset.exe -Restart }
}


Is there anyway to tell powershell to invoke-command to each server concurrently but still writing output to transcripts  (I tried running each asjob, but then I lost the output of what it was doing).

cheers for any tips!.
String :-)
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
Unlock 2 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE