Hi all,
I'm trying to get some lab autodeployment scripts setup, but am running into a licensing issue with the vCenter license. What we're doing is a fully automated deployment of the lab using PowerShell Core on Linux and everything works, except for one small piece of code:
#Add key to inventory
$labvc = Connect-VIServer $labvCenter -User $labUser -Password $labPassword -WarningAction SilentlyContinue
$lm = get-view $labvc
$lmAdd = get-view $lm.Content.LicenseManager
$lmAdd.AddLicense($vCenterKey,$null)
sleep(10)
#Assign key
$lm = get-view $labvc.ExtensionData.content.LicenseManager
$lmAM = get-view $lm.licenseAssignmentManager
$lmAM.UpdateAssignedLicense($labvc.InstanceUuid,$vCenterKey,$null)
The key is being added to the license inventory just fine, but when executing the UpdateAssignedLicence at the bottom, I get the following error:
Exception calling "UpdateAssignedLicense" with "3" argument(s): "A specified parameter was not correct: entityId"
+ $lmAM.UpdateAssignedLicense($labvc.InstanceUuid,$vCenterKey,$null ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
I've already checked that $labvc.InstanceUuid does return the proper value and that $vCenterKey is set correctly but most of the times this error keeps popping up. However, if I keep retrying the exact same code, at some point it will suddenly succeed (and I can't figure out why). It's truly just a copy-paste that I keep doing and at some point it's suddenly licensed.
Does anyone have any idea on how I can either improve the above code so it always works, or how I can resolve the issue (I realise the answer to both questions might be the same...).
Some additional information:
- vCenter version is 6.7
- PowerCLI version is 10.2
MrBoogiee