PowerCLI: Mass Shutdown of VM’s

PowerCLI: Mass Shutdown of VM’s

When I am working with test and dev VM’s I usually find I need to shut them down from time to time whilst another project is on the go. Instead of using the web vsphere client and pressing the off power button on each I use powercli so that i can save some time. The trick is to name your VM’s properly at the start of the project so for example this is the naming convention I use when making test VM’s

(TEST-PROJECTNAME-NUMBER)

for example an Asterisk project would be named as follows

TEST-ASTERISK-PBX01

TEST-ASTERISK-PBX02

So first thing i do is make sure that PowerCLI can list the correct VM’s

connect-viserver test-host
get-vm TEST-ASTERISK-PBX* | Format-Table -AutoSize

Then once I can see that it has listed the correct VM’s for shutdown I issue the following command and confirm all

connect-viserver test-host
shutdown-vmguest TEST-ASTERISK-PBX*

And that’s it

Advertisements