VMware Cloud Community
JBartholomew
Enthusiast
Enthusiast

Get-Tagassignment failing on only 1 of 7 vCenters

I have a script that I use to gather our VM inventory across our 7 vCenters that has been working great for a few years now. Suddenly about 2 weeks ago the one vCenter stopped responding to get-tagassignment correctly, and is now throwing the following error:
 

Get-TagAssignment : 7/23/2021 11:32:08 AM       Get-TagAssignment               Object reference not set to an instance of an object.
At line:1 char:1
+ Get-TagAssignment
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-TagAssignment], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTagAssignment

 

So here is all the relevant information:

The connection is 2 separate Connect-viServer commands (as we have our Prod vCenters isolated from Dev/QA)

eg.)

Connect-viserver -Server $ProdvCenter -Alllinked -credentials $prodCreds

Connect-Viserver -Server $DevQAvCenter -Alllinked -credentials $DevQACreds

 

and if I do a $Global:defaultviservers I get a list of all 7 of the vCenters

The command that is being used to gather our tags locally so I can parse them later is

$AllVMTags = Get-tagassignment -ErrorAction SilentlyContinue

and failing that have also tried

Foreach($Site in $Global:allvCenters) { 
	Write-Host "Gathering tags from: $Site"
	$AllVMTags += Get-TagAssignment -Server $Site -ErrorAction SilentlyContinue
}

and also

$Tagcats = Get-TagCategory -server $vCenter
ForEach($cat in $Tagcats) {
	Write-Host "Gathering Tags from" $cat
		$AllVMTags +=  Get-TagAssignment -Category $cat
	}

All with the same results. The gather the tags from 6 of the 7 vCenters, but not the 7th.

the only way I have managed to get it to work is:

$AllVMTags = Get-VM * | foreach {Get-Tagassignment -entity $_}

But it takes approximately 2-3x as long as any of the other ways to pull the data, and with 3000+ VMs it really adds to the runtime.

I have tried on multiple machines and they are all running the following

> Get-Module VMWare.powercli -ListAvailable | select Name, version

Name            Version
----            -------
VMware.PowerCLI 12.3.0.17860403
VMware.PowerCLI 12.1.0.17009493

> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      18362  1593

 

all of the vCenters are running 6.7.0 Build 18010599 (updated around the time of this issue starting, but 6 of 7 still working is a little odd)

If I run 'get-tagassignment -category Environment' it works fine, but if I use it in the full loop to get all the tag categories it still fails.

I have rebooted both the script server and the affected VCSA to see if thats the problem to no avail.

 

Unfortunately I am at a loss as the error is quite vague about which object is not set.

 

 

0 Kudos
3 Replies
LucD
Leadership
Leadership

Have you looked at Solved: Problem with Get-Tag and Get-TagAssignment - VMware Technology Network VMTN
and tried any of the workarounds mentioned in there?


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

0 Kudos
JBartholomew
Enthusiast
Enthusiast

Just to wrap this thread up as I hate Threads with no actual resolution.

 

After discussion with the PowerCLI group at VMWare we believe in our case we have hit a known bug with version 12.3 of PowerCLI and they believe this action should be fixed in version 12.4

0 Kudos
Ali405
Contributor
Contributor

Thanks for coming back with the resolution. I'm seeing the same thing, randomly started to happen on 1 vCenter of an estate of 80. PowerCLI 12.3, hoping it's fixed in 12.4.

0 Kudos