VMware Networking Community
bjornl
Enthusiast
Enthusiast

TAG vm in NSX-T using Get-NsxtPolicyService

I've googled around to try and find a way to use PowerCLI to tag VMs in NSX using the Get-NsxtPolicyService cmdlet. It would be much more elegant doing it there than building stings and POSTing them via the rest api, in my opinion. I did find a few examples out there, but they were targeted at the old manager api, not the new policy api.

I can handle the vCenter part, but the NSX-T cmdlet is giving me a hard time 🙂 

I've been trying along these lines:

$nsxtps = Get-NsxtPolicyService -Name com.vmware.nsx_policy.infra.tags.tag_operations
$tagspesification = $nsxtps.help.update.tag_bulk_operation.Create()
$tagspesification
$tagspesification.tag.scope = "system"
$tagspesification.tag.tag = "spl"
$tagspesification.apply_to = "423c75a9-9046-9788-2723-86c4d32b7f84"
$tagspesification.resource_type = "VirtualMachine"
$nsxtps.update()

That last 'update' command returns some less meaningful errors, depending on the variants I try. Has anyone done this successfully? I'm hoing to crach the code of the Get-NsxtPolicyService cmdlet at it seems to have a huge bag of goodies for those who know it.

0 Kudos
0 Replies