Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 49146

Re: Poweroff and Poweron 1000 VMs in Parallel

$
0
0

You can use the Start-Job cmdlet to launch these cmdlets in the background.

You probably want to impose a maximum number of jobs to run in the background, hence the MaxJobs test.

 

$script={

   param(

   [string]$VMName,

   [string]$vcId

   )


   Connect-VIServer-Session $vcId


   Get-VM-Name $VMName| Shutdown-VMGuest -Confirm:$false

}


$fileName='.\input.csv'


$MaxJobs=10


Import-Csv-Path $fileName|ForEach-Object-Process {

   $jobs=@()

   while($jobs.Count-le$MaxJob){

   $jobs+=(Start-Job-ScriptBlock $script-ArgumentList $_.VMName,$global:DefaultVIServer.SessionId)

   }

   Wait-Job-Job $jobs.Id

}


Viewing all articles
Browse latest Browse all 49146

Trending Articles



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