I have a bunch of VM names in a text file. I want to assign an NSX Security tag to all of them.
1 |
Get-Content .\InternetVMs.txt | %{ Get-VM $_ | New-NsxSecurityTagAssignment -ApplyTag -SecurityTag (Get-NsxSecurityTag internet_access) } |
To get the NSX Security tags of a bunch of VMs in a text file (so u can confirm the above worked):
1 |
Get-Content .\InternetVMs.txt | %{ Get-VM $_ | Get-NsxSecurityTagAssignment | select-object @{Name="SecurityTag"; expression = {$_.securitytag.name}}, VirtualMachine } |
These require PowerNSX BTW.
I had to do the same for a bunch of VMs in a folder too:
1 |
Get-Folder "XenDesktops" | Get-VM | %{ $_ | New-NsxSecurityTagAssignment -ApplyTag -SecurityTag (Get-NsxSecurityTag internet_access) } |
Lastly, to find all VMs assigned a security tag:
1 |
Get-NsxSecurityTagAssignment -SecurityTag (Get-NsxSecurityTag internet_access) |