VMware Cloud Community
skhan22
Contributor
Contributor

vSphere Tags Across Multiple vCenters

I'm having a problem applying vSphere tag in a vCenter (linked mode) to a specific vCenter. We've a Mgmt vCenter and prod vCenter. Here is my script:

$vms=test
foreach ($vm in $vms) { $vm | New-TagAssignment -tag "Prod" -Server (([uri]$vm.ExtensionData.Client.ServiceUrl).Host)}

Reply
0 Kudos
1 Reply
skhan22
Contributor
Contributor

NVM. I found my answer on VMTN. Here is what I did... I ran the following command to add vCenterServer property to Virula property .

New-VIProperty -Name vCenterServer -ObjectType VirtualMachine -Value {$Args[0].Uid.Split(":")[0].Split("@")[1]}

and then

Get-VM -Name vmname | New-TagAssignment -Tag "prod" -Server vCenterServer

Reply
0 Kudos