Highlighted
Contributor
Contributor

Remove-Tagassignment fails to remove tag, WebUI removes tag fine. Add tag back, and Remove-Tagassignment works

I have a batch of VMs that are exhibiting a strange behavior.

If I run:

Get-TagAssignment -Entity $vm -category $categoryname| Remove-TagAssignment

I get prompted to remove the appropriate tag, to which I say 'Yes', and the command ends with no error.  The tag is not removed though

If I remove the tag manually from the WebUI, the tag is removed as expected.  If I then re-add the same tag, I am able to run the above command and it successfully removes the tag.

I checked the tagassignment tag ID/UID are the same across runs.  This happened for both PowerCLI 11.5 and 12.0.  I have not tested on other versions, and so far as I know only affects a handful of VMs that have moved folders.  Moving the VMs had no discernible effect (i.e. not a permissions issue, also the same administrator account was used for all operations).

Thoughts or suggestions?

0 Kudos
9 Replies
Highlighted
User Moderator
User Moderator

To exclude any privilege issues, are you using the same credentials for the Connect-VIServer as for logging into the Web Client?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Contributor
Contributor

As above, the same administrator account was used for all operations.  Further, there are no accounts that have 'some tagging privileges'.  Only accounts in the Administrator group have VMWare Tagging privileges at all, and have full tagging privileges.  The account has Administrator permissions and is a member of no other groups.  There are no explicit permissions set on the VMs, only the Folders, and the Folder location had no effect on the VMs in question.

When the Remove-Tagassignment failed to remove the tag, there was no error.

0 Kudos
Highlighted
User Moderator
User Moderator

I see.
Which vSphere version is that?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Contributor
Contributor

6.7u3b

0 Kudos
Highlighted
Contributor
Contributor

Hello,

I have exactly the same issue.

Vcenter 6.7.0.42000

ESXi, 6.5.0, 16207673

when i add a new tag i can remove it with my script.

but on many vms a old tag don't untag.

I use this script to manage my veeam migration.

this morning, test on 100 VMs, ony 25 the tag was removed, and 75 not remove, i have to remove one by one on Vcenter UI.

the part of my script to remove, that the same as you @BrettK1

foreach ($vmNameRemove in $vmList) {Get-VM $vmNameRemove | Get-TagAssignment | where{$_.Tag.Name -like $tagtoremove} | Remove-TagAssignment -Confirm:$false -verbose}

and no errors when you launch the script

Need some help too Smiley Sad

0 Kudos
Highlighted
User Moderator
User Moderator

Are the VMs coming through the Where-clause?

Get-VM $vmNameRemove | Get-TagAssignment | where{$_.Tag.Name -like $tagtoremove}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Contributor
Contributor

Yes, because i do a verification at the end to show the VMs who have always the tag.

My entire script :

#fichier d'entrée

$vmList = Get-Content D:\Powercli_scripts\Tags\vm-veeam.txt

#tag à enlever de la vm

$tagtoremove = "***-HPR-VMs-STD-WIN"

#tag à ajouter à la vm

$tagtoadd = "***-HPR-VMs-STD-WIN-V10"

$datestring = (Get-Date).ToString(“yyyyMMdd-HHmmss”)

#Module VMWARE.

import-module VMware.VimAutomation.Core

$vCenter***="******"

$vCenter***="******"

connect-viserver $vCenter***

#ajout du nouveau tag

write-host "ajout du nouveau tag: $tagtoadd aux VMs"

foreach ($vmNameAdd in $vmList) {New-TagAssignment -Tag $tagtoadd -Entity $vmNameAdd}

#suppression de l'ancien Tag

Write-Host "suppression de l'ancien $tagtoremove aux VMs"

foreach ($vmNameRemove in $vmList) {Get-VM $vmNameRemove | Get-TagAssignment | where{$_.Tag.Name -like $tagtoremove} | Remove-TagAssignment -Confirm:$false -verbose}

#verification dans la foulée

Write-host "Vérification de la présence de l'ancien tag $tagtoremove aux VMs - veuillez patienter"

$errortags = foreach ($vmNameRemove in $vmList) {Get-VM $vmNameRemove | Get-TagAssignment | where{$_.Tag.Name -like $tagtoremove} | select Entity }

Write-Host "tag $tagtoremove toujours présent sur les VMs suivantes :"

$errortags

$errortags | Export-Csv D:\Powercli_scripts\tags\errorstags-$datestring.csv -NoTypeInformation

Write-host "opération terminée"

Disconnect-VIServer -confirm:$false

_____________________________________________________

(** are to anonymize my personal informations)

After the launch of the script, i have a csv with the vms who have always the tag to remove.

0 Kudos
Highlighted
User Moderator
User Moderator

I assume you are using PowerCLI 12.0?

There will shortly be a 12.1 release.

In any case, I would suggest to open an SR.

The more people mention/report this, the higher it gets on the list of issues to investigate/fix.

And PowerCLI is supported, even with a Developer Support contract.

If GSS claims otherwise, point them to PowerCLI Support Breakdown


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Contributor
Contributor

Thanks LucD

Yes i use version 12 :

PS C:\Windows\system32> Get-Module -Name VMware.PowerCLI | Select-Object -Property Name,Version

Name            Version       

----            -------       

VMware.PowerCLI 12.0.0.15947286

I'm going to try the SR.

Have a nice day

0 Kudos