Sunday, September 13, 2015

Quick ping of VM guests

Quick ping of VM guests


get-vm | sort name | Foreach {Write-Output "Guest $($_.name) up: $(Test-Connection $_ -count 1 -quiet)"}


Guest vmtest01 up: True
Guest vmtest02 up: True
Guest vmtest03 up: True
Guest vmtest04 up: True
Guest vmtest05 up: True
Guest vmtest06 up: True
Guest vmtest07 up: True
Guest vmtest08 up: True
Guest vmtest09 up: True
Guest vmtest10 up: False
Guest vmtest11 up: True
Guest vmtest12 up: True
Guest vmtest13 up: True
Guest vmtest14 up: True
Guest vmtest15 up: True




You may want to use -count 2 if your network has a tendency to drop the first ping.

Friday, September 4, 2015

Restarting all VMs in one line (AKA, why vCenter admins shouldn't leave their workstations unlocked)

We live in an interesting IT world.  A former employer once took away my second AD 'admin' account because I wasn't a Windows admin and the auditors insisted that the only people who should have separate admin accounts were Windows admins.  How backwards is that?  After they took away my separate account, I had only one AD account with all my permissions, which included highly privileged access in vCenter.  That's right - I had one account to login with, and that account had the ability to reboot, shut down, or delete every VM in the company with one line of code.  (Ok, 2 lines of code if I wasn't already connected to the vCenter servers.)  And yes, I did express my concern to management, who agreed that this change actually decreased security.  However, since the change was something that was brought up by auditors and the appearance of security is often more important than actual security, nothing was ever done to separate my privileges on the virtual side.





Get-VM | Restart-VMGuest -confirm:$false
Get-VM | Stop-VM -confirm:$false
Get-VM | Remove-VM -DeletePermanently -runasync -confirm:$false




In the first command, Restart-VMGuest requires a supported version of vmtools to be installed and running in the VM.  It will use vmtools to use the guest operating system's graceful shutdown routine.  Use Restart-VM if you want to just pull the rug out under the OS more like a hardware power cycle.




In the second command, there is no graceful shutdown and no requirement for vmtools.  It's like holding in the power button and crashing down the VM hard.  Use Stop-VMGuest if you want to try a graceful shutdown using vmtools instead.




In the last command, the -DeletePermanently flag removes the VM files from the storage instead of just removing the VM from vCenter inventory.  -RunAsync lets it run much more quickly, as it will start the delete process and move to the next delete, instead of waiting for the current delete to finish before starting the next one.