I have a script that checks for, removes old and installs new VIBs on the hosts in my cluster. Problem is I currently only have it working on one host at a time through a foreach loop. I'd like to make the script execute across more hosts in the cluster parallelly, so essentially a subset of it. Any idea how I would be able to achieve that.
Code snippet:
# Enter vCenter Server to connect to
$server = Read-Host 'Enter vCenter Server FQDN'
Connect-VIServer -Server $server
# Get ESXi hostnames
$esxiServers = @(Get-Cluster | Get-VMHost | Sort-Object -Property Name)
foreach ($esxiServer in $esxiServers) {
$Endloop=$false
# Check if ESXi is in mainternance mode, if not set it in maintenance mode
$esxi = Get-VMHost -Name $esxiServer
Write-Host
Write-Host
Write-Host (Get-Date) ": Checking if $esxiServer is in maintenance mode" -ForegroundColor Yellow
Write-Host (Get-Date) ": $esxiServer is in "(Get-VMHost $esxiServer).ConnectionState' mode' -ForegroundColor Red
if ($esxi.ConnectionState -ne 'Maintenance') {
Write-Host (Get-Date) ": Setting $esxiServer to maintenance mode" -Foregroundcolor Yellow
Get-VMHost $esxiServer | Set-VMHost -State Maintenance -Confirm:$False -RunAsync | Out-Null
sleep 10
...