Having an issue with Tags in PowerCLI I create a tag but it gives me an error its already created (creates it multiple times). I am running vsphere 6 U1 and the latest version of PowerCLI (I updated it last week.)
Here is a sample:
PowerCLI C:\scripts> Get-TagCategory -name "Production Level" | New-Tag -Name "P
RD" -Description "Production Level Servers"
Name Category Description
---- -------- -----------
PRD Production Level Production Lev...
New-Tag : 9/23/2016 8:21:59 AM New-Tag Tag with name 'PRD' already
exists in category 'Production Level'.
At line:1 char:44
+ Get-TagCategory -name "Production Level" | New-Tag -Name "PRD" -Description
"Pro ...
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Tag:String) [New-Tag], ViErro
r
+ FullyQualifiedErrorId : ViCore_TaggingServiceImpl_Tag_AlreadyExists,VMwa
re.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTag
Then when I list out the tags it looks like:
PowerCLI C:\scripts> get-tag "Test VM for Systems"
Name Category Description
---- -------- -----------
Test VM for Systems Systems Test VMs This is a samp...
Test VM for Systems Systems Test VMs This is a samp...
As you can see there are 2 tags here (Only one shows up in web client).
I can apply tags manually in the web client but I have a lot of tags and vm's to tag as we're just starting to put meta data on them, so I'm trying to get my script to do them however it won't work because there is two tags listed.
Sample of what the error looks like:
PowerCLI C:\scripts> New-TagAssignment -Tag DEV -Entity its-systst2-dev
New-TagAssignment : 9/23/2016 8:39:22 AM New-TagAssignment The
specified parameter 'Tag' expects a single value, but your name criteria 'DEV'
corresponds to multiple values.
At line:1 char:1
+ New-TagAssignment -Tag DEV -Entity its-systst2-dev
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop
]:List`1) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResu
ltsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTa
gAssignment
New-TagAssignment : 9/23/2016 8:39:25 AM New-TagAssignment The
specified parameter 'Entity' expects a single value, but your name criteria
'its-systst2-dev' corresponds to multiple values.
At line:1 char:1
+ New-TagAssignment -Tag DEV -Entity its-systst2-dev
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop
]:List`1) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResu
ltsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTa
gAssignment
New-TagAssignment : 9/23/2016 8:39:25 AM New-TagAssignment Value
cannot be found for the mandatory parameter Tag
At line:1 char:1
+ New-TagAssignment -Tag DEV -Entity its-systst2-dev
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], VimExcept
ion
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
n.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
There seems to have been a session bug that incorrectly has 2 values sometimes when the script is run. Closing out the session and doing a fresh connect to the vcenter seems to fix the issue. Just in case anybody else encounters it.
It obviously looks like you already created those tags.
You just need to create the categories with their cardinality and the tags once, so it's probably less confusing to do that in the web client.
What I think you're trying to automate is the assignment of tags to your objects (VMs). It's easy.
For example to tag all VMs in the "TEST" folder with the tag Tag1:
Get-VM -location "TEST" | New-TagAssignment -Tag "Tag1"
I recommend you run get-tag and get-tagcategory and do a spring cleaning in there.
Cheers,
the problem is it creates 2 when I create a tag, even if I make it in the web client, the webclient only shows 1 of each tag, but when you use powercli it shows 2 for some reason, when you delete 1 it deletes both, when you create 1 it actually has a "ghost secondary tag" it creates, that only shows in powercli
There seems to have been a session bug that incorrectly has 2 values sometimes when the script is run. Closing out the session and doing a fresh connect to the vcenter seems to fix the issue. Just in case anybody else encounters it.
