Al_
Enthusiast
Enthusiast

VM tags disappear. Need to confirm .PS1/Remove-TagAssignment not responsible.

Get-VICredentialStoreItem -File C:\Users\*******\AppData\Roaming\VMware\credstore\vicredentials.xml | %{
Connect-VIServer -Server $_.host -User $_.User -Password $_.Password
}
$csv = "d:\tags\prod.csv"
$category = "environment"
$Tag = "prod"
$CMDBInfo = Import-CSV "$csv"
ForEach ($item in $CMDBInfo)
{
$Name = $item.Name
Write-Host ".... Assigning tag "$Tag" in Category "$category" to VM "$Name" "
$vm = Get-VM -Name $Name
Get-TagAssignment -Entity $vm -Server (([uri]$vm.ExtensionData.Client.ServiceUrl).Host) | where{$_.Tag.Category.Name -eq $category} | Remove-TagAssignment -Confirm:$false
New-TagAssignment -Entity $vm -Tag $Tag -Server (([uri]$vm.ExtensionData.Client.ServiceUrl).Host) | Out-Null
}

 

VMs show successful tagging at beginning of execution, then the tags go away ~50% through the .CSV file.

vSphere 6.5

PowerCLI Version
----------------
VMware PowerCLI 12.0.0 build 15947286
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.0 build 15939652
VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655

 

0 Kudos
0 Replies