Ying Li at myITforum.com

PowerShell & System Center

PowerShell script to remove virtual machine from VMWare Infrastructure

Forget about the trip to Las Vegas I mentioned before, I started to like VMWare VI Tookkit the more I use it!

You just need to cultivate a habit, every time if you need to repetitively doing something, you should ask yourself if you can do it with PowerShll. More likely than not, the answer is YES, WE CAN!

Like I have a bunch of cloned vm box acting as a backup to our MOSS staging environment. We are tight on resource and so we decided to delete all the clones. Instead right click one by one, you can use the below script. Thanks Hal's comment to my previous post, it's now much simpler!

get-vm clone*|remove-vm -deletedfromdisk

But I do notice that after I remove vm this way, I got something like

clone-xyz(orphaned), you may have to add remove-inventory but I wasn't able to test this part!

Similarly you could do:

get-vm xyzmoss* |shutdown-vmguest

and

get-vm xyzmoss* |start-vm

Posted: Aug 19 2008, 08:57 PM by yli628 | with 3 comment(s)
Filed under:

Comments

halr9000 said:

Hmm that's odd.  I haven't played with remove-vm much yet.  Does every one of them get orphaned?  If so it is possible that VMW purposely didn't combine the two functions into one task.  In that case you'll need to do a remove-vm _and_ a remove-vm -delete.  Minor pain I suppose.

# August 20, 2008 8:00 PM

yli628 said:

Yes, every one I removed using remove-vm get orphaned.

But I will try the remove-vm -delete if I have another one to delete. :)

# August 20, 2008 8:29 PM

yli628 said:

I tried remove-vm -deletefromdisk option - still "Orphaned"!

# August 21, 2008 6:07 PM