VMware Cloud Community
TheSarj
Contributor
Contributor

powercli script to remove virtual machines

I am new to this and need to use a script to delete several hundered virtual machines.  My issue is that I have multiple clusters and the names are duplicated in each cluster.  I need to remove all from Cluster1 and not impact Cluster2.  I am sure something like this exists, but I have not been able to find anything really that matches or to build on.

 

Thanks!

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

You can do this with something like this

Get-Cluster -Name Cluster1 |

   Get-VM |

   Remove-VM -DeletePermanently -Confirm:$false

To make sure this actually going to do what you expect it to do, you can use the WhatIf switch on the Remove-VM cmdlet.
That way the cmdlet will tell you waht it is going to do, without actually doing it.

Get-Cluster -Name Cluster1 |

   Get-VM |

   Remove-VM -DeletePermanently -Confirm:$false -WhatIf


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos