I've been trying to use the code in the original thread I started a few months ago. It's been exceptionally helpful in demonstrating tag performance issues with our TAM and GSS case. As we move towards 6.7 I want to replicate the same tests and assign a huge batch of tags and categories to our test environment to verify we're going to be safe rolling out tags into production. However it seems like something in script is broken when interacting with 6.7. It works find (same script, same powerCLI/powershell, etc) when run against 6.0
Testing in vCenter 6.0 and succeeded in running this script: https://code.vmware.com/forums/2530#598690|4398020
Copied below to save a click (sorry about formatting - how do YOU make your code look good here?)
$CMDBInfo = Import-CSV .\cmdbinfo.csv
# Get the header names to use as tag category names
$TagCatNames = $cmdbinfo | Get-Member | Where-Object {$_.MemberType -eq "NoteProperty"} | Select-Object -Expand Name
# Create the Tag Category if it doesnt exist
Foreach ($Name in ($TagCatNames | Where-Object {$_ -ne "Name"})) {
Try {
$tCat = Get-TagCategory $Name -ErrorAction Stop
}
Catch {
Write-Host "Creating Tag Category $Name"
$tCat = New-TagCategory -Name $Name # -Description "$Name from CMDB"
}
# Create Tags under the Tag Categories
$UniqueTags = $cmdbinfo | Select-Object -expand $Name | Get-Unique
Foreach ($Tag in $UniqueTags) {
Try {
$tTag = Get-Tag $Tag -Category $tCat -ErrorAction Stop
}
Catch {
Write-Host "..Creating Tag under $Name of $Tag"
$tTag = New-Tag -Name $Tag -Category $tCat # -Description "$Tag from CMDB"
}
# Assign the Tags to the VMs/Hosts
$cmdbinfo | Where-Object {$_.($Name) -eq $Tag} | Foreach-Object {
Write-Host ".... Assigning $Tag in Category of $Name to $($_.Name)"
New-TagAssignment -Entity $($_.Name) -Tag $tTag | Out-Null
}
}
}
I went back and verified in our test lab vCenter 6.0 (latest update) that this script worked flawless.
However in vCenter 6.7 the script fails to actually assign the tag to the VM. It is able to populate tags and categories without issue but when it comes time to assign a tag to the VM,
If I nuke the categories and tags in 6.7, and manually set them up:
PS C:\Users\redacted\Desktop\Tagging Project> New-TagCategory Application -Cardinality multiple
Name Cardinality Description
---- ----------- -----------
Application Multiple
PS C:\Users\redacted\Desktop\Tagging Project> New-tag TestApp1 -category Application
Name Category Description
---- -------- -----------
TestApp1 Application
PS C:\Users\redacted\Desktop\Tagging Project> New-TagAssignment -entity TagTestVM_00 -Tag TestApp1
New-TagAssignment : 2/6/2019 11:17:20 AM New-TagAssignment Value cannot be null.
Parameter name: collection
At line:1 char:1
+ New-TagAssignment -entity TagTestVM_00 -Tag TestApp1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
Even just breaking it out further:
PS C:\Users\redacted\Desktop\Tagging Project> New-TagAssignment -Tag TestApp1 -Entity TagTestVM_00
New-TagAssignment : 2/6/2019 11:21:34 AM New-TagAssignment Value cannot be null.
Parameter name: collection
At line:1 char:1
+ New-TagAssignment -Tag TestApp1 -Entity TagTestVM_00
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
And finally from the basic command:
PS C:\Users\redacted\Desktop\Tagging Project> New-TagAssignment
cmdlet New-TagAssignment at command pipeline position 1
Supply values for the following parameters:
Tag: TestApp1
Cannot convert the "TestApp1" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.Tagging.Tag".
Interesting twist to this all and worthy of mention - I opened a case with GSS and they punted because I didn't have SDK support, even though it works with all other vCenters except my 6.7 in the lab. I gave up and blew it away and redeployed a 6.7 VMCA and the null error was gone.
We'll never know what was wrong with the lab vCenter but my fix was to replace it seemed to work. All the scripts that were failing before now work.
The error with the New-TagAssignment is a known issue.
Which PowerCLI version are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the confirmation. I'm glad I'm not losing my mind (more than I already am).
11.1.0.11289667 VMware.PowerCLI
As an alternative try the community module VMware.Community.CISTag from Kyle.
There is a blog post with details.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Interesting twist to this all and worthy of mention - I opened a case with GSS and they punted because I didn't have SDK support, even though it works with all other vCenters except my 6.7 in the lab. I gave up and blew it away and redeployed a 6.7 VMCA and the null error was gone.
We'll never know what was wrong with the lab vCenter but my fix was to replace it seemed to work. All the scripts that were failing before now work.
Great you issue is fixed, although a fresh install isn't the desired solution :smileygrin:
On the GSS reply (and for future readers of this thread).
GSS sometimes may tell you that you need a Developer Support contract for PowerCLI, but that is not true in all cases.
Point them to PowerCLI Support Breakdown
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yeah I even provided that link with clear explaination that I was fairly sure it was vcenter and not powerCLI and they replied within minutes with a denied response. I was pretty disappointed.