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

2 comments:

Post a Comment

Who am I

My photo
I’m and IT specialist with over 15 years of experience, working from IT infraestructure to management products, troubleshooting and project management skills from medium to large environments. Nowadays I'm working for VMware as a Senior Consultant, helping customers to embrace the Cloud Era and make them succefully on this journay. Despite the fact I'm a VMware employee these postings reflect my own opnion and do not represents VMware's position, strategies or opinios.

Most Viewed Posts

Blog Archive