Files
powerwall/esxi-scripts/vm-shutdown.ps1

16 lines
730 B
PowerShell
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env pwsh
. /opt/idssys/powerwall/settings.ps1
#Connect-VIServer -Server $VCENTERHOST -Protocol https -User $VCENTERUSER -Password $VCENTERPASS | Out-Null
Connect-VIServer $VCENTERHOST -Force -Protocol https -User $VCENTERUSER -Password $VCENTERPASS
$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
Get-VMHost | Where {$_.Name -eq $vmhost} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'}
}
Disconnect-VIServer -Server $VCENTERHOST -Force Confirm:$false