Hi,
I'm trying to add "tags" on my VMs using powercli.
I get nasty red error messages.... But the VMs gets the tag applied.
New-TagAssignment : 2017-12-05 11:12:35 New-TagAssignment The given key was not present in the dictionary.
At line:13 char:9
+ New-TagAssignment -Entity $vm -Tag $lintag
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], CisException
+ FullyQualifiedErrorId : ViCore.Impl.V1.Service.Tagging.Cis.TaggingServiceCisImpl.NewTagAssignment.Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
Also, when iI run questions against my vCenter about applied tags I don't get the accurate information.
vCenter version 6.5.0.5300
PS C:\Windows\system32> Get-PowerCLIVersion
PowerCLI Version
----------------
VMware PowerCLI 6.5.1 build 5377412
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component 6.5 build 6983166
VMware VimAutomation Core PowerCLI Component 6.5 build 6234650
Advice?
Regards,
Johan
Could you give us some info?
I assume that the content of $lintag was obtained through Get-Tag?
And how did you define the Tag Category that this Tag belongs to?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I'm running the following script.
$wintag = Get-Tag -Name 'srv-windows'
$lintag = Get-Tag -name 'srv-linux'
#$othertag = Get-Tag -name 'nobackup'
foreach($vm in (Get-folder 'sportsbook' -Type VM | Get-VM)){
If ($vm.Guest.OSFullName -like "*win*") {
New-TagAssignment -Entity $vm -Tag $wintag
}
elseif ($vm.Guest.GuestFamily -like "linuxguest") {
New-TagAssignment -Entity $vm -Tag $lintag
}
}
Regards,
Johan
Thanks, that looks ok.
But you should also check the Tag Category in which the Tags are created.
If the Tag Category has a Cardinality of 'Single' and there is already a Tag from the same Tag Category assigned, the new assignment will not work.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PS C:\Windows\system32> Get-TagCategory
Description : Veeam Backup TAGs
Cardinality : Single
EntityType : {VirtualMachine}
Id : urn:vmomi:InventoryServiceCategory:6aadd96c-b633-4998-946d-38960f0c8fe8:GLOBAL
Name : vbr
Uid : /VIServer=xxx\johm@xxx-vcsa-01:443/TagCategory=urn:vmomi:InventoryServiceCategory:6aadd96c-b633-4998-946d-38960f0c8fe8:GLOBAL/
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
So this is wrong?
Not necessarily.
But you can only have 1 tag from that category assigned to a VM.
If you have tag1 and tag2, both belonging to that category, you can only assign one of them to the VM.
You will have to remove the tag that is already assigned before you can assign a new one from that same category.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I understand.
But I only have 1 tag assigned to my VMs.
If I remove this tag (no tags present on VM) , and then try to apply it again, I get the same error message.
"The given key was not present..."
(The tag will be applied though)
My vCenter crashed some weeks ago and I had to reinstall it.
Don't know if this could have something to do with my problem.
Ok, that is one possibility verified.
Are you connected to multiple vSphere servers?
Check what is in $global:defaultviservers.
Are the variables you use in the New-TagAssignment holding single objects? Not more than one object?
Is there a VirtualMachine object in the $vm variable, or a string with the name of the VM?
Same question for the variable used for the Tag
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, that is one possibility verified.
Are you connected to multiple vSphere servers?
Check what is in $global:defaultviservers.
I'm only connected to 1 vCenter
Are the variables you use in the New-TagAssignment holding single objects? Not more than one object?
Yes , i list VMs in a specific folder and then use > foreach($vm in (Get-folder 'ext' -Type VM | Get-VM))
I just created a new VM named 'jjjjj' and then tried to apply a tag.
$lintag = Get-Tag -name 'ext-linux'
$vm = get-vm 'jjjjj'
New-TagAssignment -Entity $vm -Tag $lintag
Uid : /VIServer=xxx\johm@xxx-vcsa-01:443/VirtualMachine=VirtualMachine-vm-10271/TagAssignment=/Tag=urn:vmomi:InventoryServiceTag:d667e6d8-b5b0-4f1a-b0e7-66d32a469b16:GLOBAL/
Tag : ext-linux
Entity : jjjjj
Id : com.vmware.cis.tagging.TagAssociationModel
Name : com.vmware.cis.tagging.TagAssociationModel
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
Works just fine!
When I had issues with my previous vCenter, I took a backup of the database, I then installed a new vcsa appliance , then I restored the database.
Feels like that the problem is with the vCenter database and duplicate tag entries. (Haven't had issues with applying tags this way before)
I will ask vmware for support.
Many thanks for your help/feedback.
Much appreciated!!
Did you resolve this with support? What was the remedy?
We have a similar issue I think...A restored vCenter too.... I see this issue on get-tagassignment...
Which PowerCLI version are you running?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference