Stage 1 shutdown for UPS, the vm’s we don’t care about

Stage 1, shutdown down vm’s we don’t care about
[powershell]
add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer vcenter.www.alanrocks.com
#stage 1, shutdown or stop vm’s not on this list
$vmsilike = "dc1","vcenter","VPNstuff","quickbooks","dc2","files","wordpress-win","exchange2010","sharepoint","sql"
$vmson = (get-vm | where {$_.powerstate -eq "PoweredOn"})
$dievms = ($vmson -like $vmsilike)
foreach ($vmso in $vmson){if ($vmsilike -notcontains $vmso.Name){
# debug Write-Host $vmso.name "shut this bitch down"}}
$fvm = Get-VM $vmso
#findtoolsver
$toolver = (get-vm $fvm |% {get-View $_.id} | select @{Name="toolsver"; expression={$_.config.tools.toolsversion}})
if ($toolver.toolsver -gt 10000){$fvm | Stop-VM -Confirm:$false}
if ($toolver.toolsver -le 10000){$fvm | Shutdown-VMGuest -Confirm:$false}
}}
[/powershell]

Leave a Reply

Your email address will not be published.