This commit is contained in:
2024-02-02 08:46:03 -06:00
parent 95d32aafb9
commit b286ff77de
2 changed files with 10 additions and 2 deletions

View File

@@ -6,7 +6,15 @@ Connect-VIServer -Server $VCENTERHOST -Protocol https -User $VCENTERUSER -Passwo
$vmhosts=$args[0].Split(",")
Foreach ($vmhost in $vmhosts)
{
Get-VMHost | Where {$_.Name -eq $vmhost} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'} | Shutdown-VMGuest -Confirm:$false
$vms=Get-VMHost | Where {$_.Name -eq $vmhost} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'}
Foreach ($vm in $vms)
{
$migrating=Get-Task | ?{$_.ObjectId -match 'VirtualMachine'} | Select @{N='VM';E={(Get-View -Id $_.ObjectId).Name }},State,Description | where {$_.VM -eq $vm -and $_.Description -like '*Relocate*' -and $_.State -eq 'Running'}
if ([string]::IsNullOrEmpty($migrating)) {
write-host "Shutting down "+$vm
#Get-VM $vm | Shutdown-VMGuest -Confirm:$false
}
}
}
Disconnect-VIServer -Server $VCENTERHOST -Force Confirm:$false