PowerCLI

 View Only
  • 1.  powercli script to remove virtual machines

    Posted Jan 20, 2019 07:53 PM

    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!



  • 2.  RE: powercli script to remove virtual machines

    Posted Jan 20, 2019 08:02 PM

    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