Thursday, October 28, 2010

VMware script to delete/remove VMs, guests

I have to admit since I started playing with PowerCLI I’ve been enjoying it more and more.

A few weeks ago I needed to delete 50 VMs from the environment and I realized I would give the script a shot.
Of course I could do that through Virtual Center, but it would take some time to do it manually.

So, here’s my script which deleted all the 50 VMs in about 08 minutes ; )

Assuming that you have a txt file with your guest’s name one per line.
Mine was c:\temp\servers.txt (replace this on the script for you file name)

Open PowerCLI
Connect on VC: Connect-VIServer –Server “your_VC_goes_here”
Get-Content c:\temp\servers.txt | foreach { Remove-vm $_ -DeleteFromDisk -Confirm:$false }

Have a good one


Post a Comment

Who am I

My photo
I’m an IT specialist with over 15 years of experience, working from IT infrastructure to management products, troubleshooting and project management skills from medium to large environments. Nowadays I'm working for VMware as a Consulting Architect, helping customers to embrace the Cloud Era and make them successfully on their journey. Despite the fact I'm a VMware employee these postings reflect my own opinion and do not represents VMware's position, strategies or opinions. Reach me at @dumeirell

Most Viewed Posts

Blog Archive