Rebooting a virtual machine via Task scheduler

Since the Scheduled Tasks in vCenter ain’t exportable, I went ahead and wrote a rather simple script, which lets me do this in Windows own Task Scheduler. What this script does, is initiate a graceful shutdown and if the VM isn’t shutdown within 60 seconds (12 * 5 seconds) it simply powers the VM off and immediately after that powers it back on.

Before this implementation in PowerCLI, I needed three tasks for each VM that was to be scheduled. And when migrating vCenters (and I usually do an empty install) vCenter’s scheduled tasks are not exportable, thus you need to re-create the tasks on the new vCenter by yourself again, which for more than four virtual machines is really a pain in the ass …

Update: well, found an error that caused shit not to work … Basically Stop-VM also needs the object for $VMname, otherwise the whole point of waiting for the VM to be stopped is kinda moot (seeing as Stop-VM never stops obsessing about not having a Get-VM object or a VM name to work with).

VMware vCenter: is not connected

Well, today I once again had the case where a virtual machine (in my case a Virtual Machine Template) was kinda stuck. You couldn’t remove the template (as in the entries for “Remove from inventory” was grayed out) and you couldn’t re-add the Virtual Machine’s VMX from the datastore browser either.

VI Client - Disconnected templates
VI Client – Disconnected templates

Though, a simple putting the host into maintenance mode and rebooting helped that problem. Maybe there is a simpler solution for this, I just don’t know about it.

Thanks to Sven in #1, I now know that simple solution for my problem!

Half a minute, and a heart-stopping moment later (all VM’s on that host turn grey after the first update) the VM’s are accessible again. Thanks again to Sven!