Quantcast
Viewing all articles
Browse latest Browse all 49146

Re: Poweroff and Poweron 1000 VMs in Parallel

To cover that we can indeed adapt the background job script.

 

$script={

   param(

   [string]$VMName,

   [string]$vcServer,

   [string]$vcId

   )


   Import-Module VMware.VimAutomation.Core


   Connect-VIServer-Server $vcServer-Session $vcId


   $vm=Get-VM-Name $VMName

   if($vm.Guest.State-eq"Running"){

  Shutdown-VMGuest -VM $vm-Confirm:$false-RunAsync

   }

   else{

   Stop-VM-VM $vm-Confirm:$false-RunAsync

   }

}


$fileName='.\input.csv'

$MaxJobs=10


$jobs=@()


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

   if($jobs.Count-le$MaxJobs){

   $job=(Start-Job-Verbose -ScriptBlock $script-ArgumentList $_.VMName,$global:DefaultVIServer.Name,$global:DefaultVIServer.SessionId)

   $jobs+=$job

   }

   else{

   Wait-Job-Job $jobs

   $jobs=@()

   }

}


Viewing all articles
Browse latest Browse all 49146

Trending Articles



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