I needed a script that would power off or on all the VMs of a particular naming type (eg the name began with the same few letters) in a particular cluster.
eg "power.ps1 SW MI off" Will power off all VMs beginning with MI in cluster(s) beginning with SW.
It does some error checking, ie it won't power on a VM that is already powered on.
I do use it with the server IP, user and password hard coded, dropping the user and password will pop up the expect msgbox.
I've no doubt that someone can take my 40 lines of code and do it in five
edit:
To power off VMs it uses "Shutdown-VMGuest $VM", this will fail if VMware tools is not running, a check could be added for VMware tools and in it's absents "Stop-VM $VM" be used instead.
I'd write things like this into a function and store it in my profile. (As well as Add-PSSnapIn.)
My attempt to do it in five lines: see attachment.
Hugo
I'd write things like this into a function and store it in my profile. (As well as Add-PSSnapIn.)
My attempt to do it in five lines: see attachment.
Hugo
Thanks Hugo. I knew I was using too many curly braces.