Stage 2 Shutdown vm’s we sorta care about

[powershell]
add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer vcenter.alanrocks.com
#stage 2, shutdown or stop vm’s not on this list
$vmsilike = "dc1","vcenter","dc2","files","exchange2010","sql","wordpress-win"
$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. Required fields are marked *