top of page
  • Rajeshkumar M

vSphere Tags to NSX-T Tags

I created a simple powercli script to copy the vSphere Tags to NSX-T, it helped me to copy the NSX-T tags on the recovery VM's in non-federated/local NSX-T managers. Since SRM retain the vSphere TAG's on the recovery side and i was able to create NSX-T tags from vSphere Tags.

Please note i have copied vSphere tag categories to NSX-T tag scope, i have an array variable($tagCategory) in my script to include the vSphere tag categories and the tags under these categories copied to NSX-T also i have array to include variable($clusterName) for clusters as well.

Connect-VIServer $vSphereFQDN -User $vSphereUser -Password $vSpherePass
Connect-NsxServer $nsxFQDN -User $nsxUser -Password $nsxPass
$allNSXVMs = Invoke-ListAllVirtualMachines
foreach($vm in get-vm -Location $clusterName){
$nsxVM=$allNSXVMs.Results | ? { $_.DisplayName -eq $ }
foreach($tag in $vm | Get-TagAssignment -Category $tagCategory)
Write-Host($nsxVM.DisplayName + " "+$tag.Tag.Name + " " + $tag.Tag.Category + " "+$nsxVM.ExternalId)
$tags = $tags+(Initialize-Tag -Scope $Tag.Tag.Category -_Tag $Tag.Tag.Name)
if($tags.count -gt 0 )
$tagupdate = Initialize-VirtualMachineTagsUpdate -Tags $tags -VirtualMachineId $nsxVM.ExternalId
Invoke-TagVirtualMachine -EnforcementPointName default -VirtualMachineTagsUpdate $tagupdate
$tags = $null
Disconnect-NsxServer $nsxFQDN 
Disconnect-VIServer $vSphereFQDN -Confirm:$false

49 views0 comments

Recent Posts

See All

vIDM Locl user password reset without email link

When resetting config admin or any local user password in VMware identity manager will trigger an email link, if in case the smtp is not working/configured we can use API call to reset the password. Y

Copy NSX-T group's shell script

Automated copy of NSX-T local group to another NSX-T #!/bin/bash #source and destination credentials susername="username" spassword="password" dusername="username" dpassword="password" sfqdn="nsx-l-01


bottom of page