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.
$vSphereFQDN="vcenter-fqdn/IP"
$vSphereUser="username"
$vSpherePass="password"
$nsxFQDN="NSX-fqdn/IP"
$nsxUser="username"
$nsxPass="password"
$clusterName=@("Cluster01","Cluster02")
$tagCategory=@("NSX-Sync01","NSX-Sync02")
Connect-VIServer $vSphereFQDN -User $vSphereUser -Password $vSpherePass
Connect-NsxServer $nsxFQDN -User $nsxUser -Password $nsxPass
$allNSXVMs = Invoke-ListAllVirtualMachines
foreach($vm in get-vm -Location $clusterName){
$tags=@()
$nsxVM=$allNSXVMs.Results | ? { $_.DisplayName -eq $vm.name }
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
$tagupdate
Invoke-TagVirtualMachine -EnforcementPointName default -VirtualMachineTagsUpdate $tagupdate
}
$tags = $null
}
Disconnect-NsxServer $nsxFQDN
Disconnect-VIServer $vSphereFQDN -Confirm:$false
Comments