VMware Cloud Community
jklimczak21
Enthusiast
Enthusiast

ProcessVM "ServerName"

I have a script that i have been Runing on a list of Servers that i add a line to my script

ProcessVM "ServerName"

ProcessVM "ServerName"

ProcessVM "ServerName"

The Issue is the script runs on one server at a time. How do i get it to run on say a Value of servers at once say

Process=4

Any help would be greate

0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership

You can use the PowerShell Start-Job cmdlet to start each command as a seperate job.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
jklimczak21
Enthusiast
Enthusiast

Would you be able to Give me an example Sorry new to powershell and CLI 

0 Kudos
RvdNieuwendijk
Leadership
Leadership

An example that also limits the number of concurrent jobs is:

$NumberOfConcurrentJobs = 4
Get-Content -Path Servers.txt |
ForEach-Object {
 while ((Get-Job | Measure-Object).Count -gt $NumberOfConcurrentJobs)
 {
   Start-Sleep -Seconds 1
 }
 Start-Job -ScriptBlock {ProcessVM $_}
}
Wait-Job

In the file servers.txt you have to specify the names of the vm's. One name on each line.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
jklimczak21
Enthusiast
Enthusiast

Thanks This way ill have to re-do my script it would take me a long time I try to find a new way thanks 

0 Kudos