VMware Cloud Community
JBartholomew
Enthusiast
Enthusiast
Jump to solution

Adding Multiple Word Tags

I have been working on a script to automate the arduous task of tagging our 1500+ VMs.

I have run into a bit of an issue with adding tags to VMs that consist of multiple words.

what I have done is created an array that lists all of the unique tags, and then goes through and compares them to the existing tags on the machine, and if they don't match, it updates the tag.

The Checking, etc works fine, the issue I have is if I have a tag that contains multiple words in it, ie.) "Flint Core" the script fails with the error:

New-TagAssignment The specified parameter 'Tag' expects a single value, but your name criteria 'Flint Core' corresponds to multiple values.   

At line:36 char:6

+ New-TagAssignment -Entity $VMName.Name -Tag "$TagName"}

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo: InvalidResult: (System.Collecti...dObjectInterop]:List`1) [New-TagAssignment], VimException

+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment

so to me it looks like it is trying to assign both Flint and Core as individual tags, and it fails as the Tag Category is set to Single Cardinality.

The $Tagname Object only holds the value 'Flint Core'

if I try to add it manually by substituting $Tagname for the actual tag name (With/without single or double quotes) it still returns the same result.

The name is a valid Tag, as I can see it, assign it, and read it from vCenter as a multiple word Tag

can anyone tell me how to get Powercli to allow me to add these multiple word tags?

Thanks

1 Solution

Accepted Solutions
JBartholomew
Enthusiast
Enthusiast
Jump to solution

well I figured out what I had done, and it was rather silly. The issue came down to that we actually had tags with the same value but different Tag Categories, so it had nothing to do with the name itself.

the issue was we had a Client named 'Flint Core' and also a location of 'Flint Core' and PowerCLI couldn't determine which one was required. Renaming the one tag in the spreadsheet resolved the issue.

View solution in original post

2 Replies
jpsider
Expert
Expert
Jump to solution

this might sound a bit silly, but why not use an underscore?

flint_core

or hyphen

flint-core

Is there a need for it to be two words? if so, why not add 2 tags?

Reply
0 Kudos
JBartholomew
Enthusiast
Enthusiast
Jump to solution

well I figured out what I had done, and it was rather silly. The issue came down to that we actually had tags with the same value but different Tag Categories, so it had nothing to do with the name itself.

the issue was we had a Client named 'Flint Core' and also a location of 'Flint Core' and PowerCLI couldn't determine which one was required. Renaming the one tag in the spreadsheet resolved the issue.