Search code examples
powershellvmwarepowercli

Powershell script to Find all VMs without a security tag and group


I have powercli module installed and cannot get powernsx to work no matter what I try, so I'm limited to direct API calls to NSX.

The goal is to report on all VMs that do not have a security tag applied.

I know i can see all VMs with Get-VM, and I can get all security tags calling https://10.x.x.x/api/2.0/services/securitytags/tag

That security tag call will only return the number of VMs it's applied to, and not the names. I need the names so I can compare to the output from Get-VM.

Does anyone know how to see the names of all the VMs that have security tags from NSX? The issue is sys admins spin up new servers and do not tag them. Need to see which ones are untagged.


Solution

  • See if this command helps you find what you are looking for, (reference)

    Get-VM | Get-NsxSecuritytagassignment | select-object @{Name="SecurityTag"; expression = {$_.securitytag.name}}, VirtualMachine