ghman
Enthusiast
Enthusiast

Mass delete vWires without VMs attached

Jump to solution

Is there an easy way (api call) to remove all logical switches (vWires) in NSX-V that have no VMs attached that belong to a specific transport zone.

I have 2270 vWires belonging to TransportZ2 that are no longer being used and all of the VMs that were attached have been deleted from disk.

How can I perform a mass delete? Keeping in mind that I have another 300 vWires with VMs attached that I do not want to delete.

Thank you,

GH

0 Kudos
1 Solution

Accepted Solutions
aggarwalvinay31
Enthusiast
Enthusiast

You can use PowerNSX to achieve this task. Outline of solution would be to use a variable to store names of logical switches. You can loop through and remove them one by one:

Script below is not tested (USE CAUTION)

$vwiresname = get-content vwires.txt

foreach($vwire in $vwiresname) {

     Get-NsxLogicalSwitch $vwire | RemoveNsxLogicalSwitch

}

Please note: PowerNSX is open source and not developed as an official product, PowerNSX is not supported by VMware, and comes with no warranties, express or implied.

Reference: https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/products/nsx/vmware-automating-vsp...

Hope this helps.

View solution in original post

0 Kudos
2 Replies
aggarwalvinay31
Enthusiast
Enthusiast

You can use PowerNSX to achieve this task. Outline of solution would be to use a variable to store names of logical switches. You can loop through and remove them one by one:

Script below is not tested (USE CAUTION)

$vwiresname = get-content vwires.txt

foreach($vwire in $vwiresname) {

     Get-NsxLogicalSwitch $vwire | RemoveNsxLogicalSwitch

}

Please note: PowerNSX is open source and not developed as an official product, PowerNSX is not supported by VMware, and comes with no warranties, express or implied.

Reference: https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/products/nsx/vmware-automating-vsp...

Hope this helps.

View solution in original post

0 Kudos

Sadly there is no API call to achieve that.

What you can do, is work with vcenter first and then nsx.

List all the VMs connected to that portgroup (LS portgroup) using powercli:

$pgName = 'PortgroupName'

$pg = Get-View -ViewType Network -Property Name,VM -Filter @{Name=$pgName}

Get-View -Id $pg.Vm -Property Name | Select-Object -ExpandProperty Name | Export-csv C:\out.csv

(maybe need review used it long time ago)

And then, you can delete using API call or UI the LS.

Triple VCIX (CMA-NV-DCV) | vExpert | MCSE | CCNA
0 Kudos