MrBoogiee
Enthusiast
Enthusiast

Exception calling "UpdateAssignedLicense" with "3" argument(s): "A specified parameter was not correct: entityId"

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

0 Kudos
13 Replies
LucD
Leadership
Leadership

Can you try adding the following loop after you Add the new license, and before trying to assign it?

while(-not ($lmAdd.Licenses | where{$_.Key -eq $vCenterKey})){

    sleep 2

    $lmAdd.UpdateViewData()

}


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

0 Kudos
APJ7033
Enthusiast
Enthusiast

I have been struggling with this exact same issue, what I found was, even though I was getting the exception, the licence key was actually being applied as expected. So added to the inventory and associated to the VC. My work around for the exception is similar to the below

$old_ErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'SilentlyContinue'

$LicenseAssignmentManager.UpdateAssignedLicense($Entity, $lic, $Null)

$ErrorActionPreference = $old_ErrorActionPreference

If ($LicenseAssignmentManager.QueryAssignedLicenses($Entity)[0].AssignedLicense.LicenseKey -match $Lic){

     <# SUCCESS CODE GOES HERE #>

}

Else

{

          <# FAILED CODE GOES HERE #>

}

0 Kudos
KaruneshThakur
VMware Employee
VMware Employee

This exception is due to not proper value of "$labvc.InstanceUuid."

"$labvc.InstanceUuid" does not throw proper value in some topology("$labvc.InstanceUuid" works in some topology and give proper entity ID.)

I also observed same issue and fixed by below script.

If you are getting above exception, you can try below code.it will work.

=====================================================================================================

$serverstatus = Connect-VIServer -server $VCIp -user $VCUsername -Password $VCPassword

$exitCode = 0

if($serverstatus.IsConnected){

              Write-Host "Connected to vCenter server, Installing vCenter License"

              $serviceInstance = Get-View ServiceInstance -Server $serverstatus

              $licenseManagerRef=$serviceInstance.Content.LicenseManager

              $licenseManager=Get-View $licenseManagerRef

              $licenseManager.AddLicense($VCLicense,$null)

              $licenseAssignmentManager = Get-View $licenseManager.LicenseAssignmentManager

              $vcUuid = $serviceInstance.Content.About.InstanceUuid

              $vcDisplayName = $serviceInstance.Content.About.Name

              Write-Host "Assigning vCenter Server License"

              $uuid=$serverstatus.InstanceUuid

    try {

            $licenseAssignmentManager.UpdateAssignedLicense($vcUuid,$VCLicense,$vcDisplayName)

        }

                catch {

                                $ErrorMessage = $_.Exception.Message

                                Write-Host $ErrorMessage

                                exit 1

                }

                disconnect-VIServer -server * -force -confirm:$false

}

========================================================================================================

0 Kudos
LucD
Leadership
Leadership

Thanks for sharing that, but I'm not sure what you "fixed" with that code?
You are using a try-catch construct to capture the exception, but the issue is still potentially there.

Or am I missing something?


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

0 Kudos
KaruneshThakur
VMware Employee
VMware Employee

As this exception is due to  value of first parameter(entity id) of  UpdateAssignedLicense method ($lmAM.UpdateAssignedLicense($labvc.InstanceUuid,$vCenterKey,$null)).

I used  $serviceInstance.Content.About.InstanceUuid  to get  entity id  instead of  $labvc.InstanceUuid(in your case).

Please check how i am taking entity id value  which is  first parameter of  UpdateAssignedLicense method.

$serverstatus = Connect-VIServer -server $VCIp -user $VCUsername -Password $VCPassword

$serviceInstance = Get-View ServiceInstance -Server $serverstatus

$vcUuid = $serviceInstance.Content.About.InstanceUuid

And,  $vcUuid  is being passed as first parameter of  UpdateAssignedLicense method.

In your case:-

$labvc = Connect-VIServer $labvCenter -User $labUser -Password $labPassword -WarningAction SilentlyContinue

And,  $labvc.InstanceUuid  is being passed as first parameter of  UpdateAssignedLicense method which is entity id .i observed  ,$labvc.InstanceUuid  does not give proper value of  entity(where you are going to assign license) in some topology.

So please  try to get  entity id value  as below .hope it will help.

$serverstatus = Connect-VIServer -server $VCIp -user $VCUsername -Password $VCPassword

$serviceInstance = Get-View ServiceInstance -Server $serverstatus

$vcUuid = $serviceInstance.Content.About.InstanceUuid

0 Kudos
usmabison
VMware Employee
VMware Employee

I have a similar issue ...

I can add licenses just fine, when assigning, the VSAN errors out when I try:

$LicenseAssignmentManager.UpdateAssignedLicense($Cluster.ExtensionData.MoRef,$vsanLicenseKey,"$null")

The $Cluster.ExtensionData.MoRef looks to be empty ... and throws the error:

Exception calling "UpdateAssignedLicense" with "3" argument(s): "A specified parameter was not correct:
entityId"
At line:1 char:1
+ $LicenseAssignmentManager.UpdateAssignedLicense($cluster.ExtensionDat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

On an aside, some code obtained from the VSAN PowerCLI Cookbook 1.7 page 54 shows:

$ClusterComputeResource = (Get-Cluster -Name $Cluster | Get-View) 

to obtain the cluster compute resource, not to be mistaken for the cluster .. the code when run, throws the error:

Get-View : 3/9/2021 7:45:52 AM Get-View Object reference not set to an instance of an object.
At line:1 char:57
+ $ClusterComputeResource = (Get-Cluster -Name $Cluster | Get-View)
+ ~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-View], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotN
etInterop.GetVIView

Not sure why this error is thrown -- argh ...

Just when I thought I was close ...

 

0 Kudos
LucD
Leadership
Leadership

Did you already try to stop/start your PowerShell session?

In the worst case, you could try a removal and a fresh install of PowerCLI.


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

0 Kudos
usmabison
VMware Employee
VMware Employee

I did .. multiple times ...

Will do ...

Tags (1)
0 Kudos
usmabison
VMware Employee
VMware Employee

No luck ...

I uninstalled PowerCLI completely; reinstalled (12.2) ... started over ...

Still a problem with the assignment of the license. I have three licenses I am trying to assign. The vcenter works like a charm ... the other two ... sad face ... throwing an error on "entityId" being an incorrect parameter ...

I am not worried about the vsphere license at this point - i may just have the wrong reference (I thought $Datacenter.Uid was correct) ... but I will look into this one more ... the VSAN license is what I am asking about here ...

Here is the code i used:

#############################

## Define variables
$Datacenter = Get-Datacenter -Name $ADShort -ErrorAction SilentlyContinue
$Cluster = Get-Cluster -Name $ADShort -ErrorAction SilentlyContinue
$LicenseManager = Get-View $global:DefaultVIServer.ExtensionData.Content.LicenseManager
$LicenseAssignmentManager = Get-View $LicenseManager.LicenseAssignmentManager

## Create Array of License Keys - (vc7,vsan7,vsphere7e+)
$Licenses = @("my","arrayof","licensekeys")

## Add Licenses if not already added
$ExistingLicenses = $LicenseManager.Licenses.LicenseKey
$LicensesToAdd = $Licenses | where-object {$_ -notin $ExistingLicenses}

ForEach ($License in $LicensesToAdd)
{
Write-Host "Adding License " + $License
$LicenseManager.AddLicense($License,$null)
}

## Assign vCenter license to this server
$MajorVersion = $VC.version.split(".")[0]
$VCLic = ($LicenseManager.Licenses | where {$_.Name -like "*vCenter*" -and $_.Name -like "*$MajorVersion*"} | select -first 1).LicenseKey ## Select a single vCenter license
$VSANLic = ($LicenseManager.Licenses | where {$_.Name -like "*vSAN*"} | select -first 1).LicenseKey ## Select a single vCenter license
$VSPHERELic = ($LicenseManager.Licenses | where {$_.Name -like "*vSphere*" -and $_.Name -like "*$MajorVersion*"} | select -first 1).LicenseKey ## Select a single vCenter license

$LicenseAssignmentManager.UpdateAssignedLicense($VC.InstanceUuid,$VCLic,$Null)
$LicenseAssignmentManager.UpdateAssignedLicense($Cluster.ExtensionData.MoRef,$VSANLic,$Null)
$LicenseAssignmentManager.UpdateAssignedLicense($Datacenter.Uid,$VSPHERELic,$Null)

#############################

0 Kudos
LucD
Leadership
Leadership

Can you try with this?

$LicenseAssignmentManager.UpdateAssignedLicense($global:DefaultVIServer.ExtensionData.Content.About.InstanceUuid,$VCLic,$null)
$LicenseAssignmentManager.UpdateAssignedLicense($Cluster.ExtensionData.MoRef.Value,$VSANLic,$Null)
Get-VMHost -Location $Datacenter | ForEach-Object -Process {
    $LicenseAssignmentManager.UpdateAssignedLicense($_.ExtensionData.MoRef.Value,$VSPHERELic,$Null)
}


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

0 Kudos
usmabison
VMware Employee
VMware Employee

Okay. That worked ... with one small wrinkle (that is hopefully easily remedied) ...

After adding the licenses (using ForEach ($License in $LicensesToAdd) ...

I refreshed my vsphere client and voila .. there I could see the new licenses that were just added -- good ...

For good measure, using Powershell ISE, I just ran $LicenseManager.Licenses, to make sure I could see the licenses there. They were not there.

...

So I wonder, is there some sort of lag between when the vsphere client shows the licenses, and when the license manager sees them? Or do I need to somehow refresh the license manager data?

Once I killed my PowerCLI session, ran it again, I could see the licenses in license manager using $LicenseManager.Licenses and the rest worked ...

Similarly, when I manually unassigned the license keys using the vsphere client, and removed them, $LicenseManager.Licenses did not reflect the change ... even disconnecting and reconnecting to vcsa did not affect this behavior. Even (in my case) killing the script and re-running it ...

I thought "Get-View" queries the License Manager entity ... sooo ... am i just missing something basic here?

I should maybe also mention that this customer environment is an enclave (of sorts), so all build/deploy work is done on a closed network (I hope that this part does not matter) ...

 

I do appreciate your assistance in this effort, and happy to donate to your 'dollar jar' if you have one!

0 Kudos
LucD
Leadership
Leadership

These vSphere objects are not automatically refreshed.
You can reacquire them or use the UpdateView method most of these vSphere objects have.


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

usmabison
VMware Employee
VMware Employee

Well ... 

Using $LicenseManager.UpdateViewData.Invoke() seems to have worked ... 

Thanks again for your time and help!

Where do I send the check?

 

Tags (1)
0 Kudos