VMware PowerCLI

The Best User Interface for your VMware Datacenter!

PowerCLI for Licenses

It would be great to have Cmdlets for adding/removing/assigning/getting licenses via PowerCLI for all relevant products. i.e. ESXi license, vCenter license, vSAN License etc.


This would help improve the ability to add/assign licenses quickly but also to help with reporting

  • David Menzies
  • Sep 18 2017
  • Attach files
  • Brian Parks commented
    6 Aug, 2018 03:08pm

    I'm using this code (modified from something I found on Internet). You can add multiple license keys, and the vCenter license key will be assigned.  I've not found anything to determine the currently assigned license key for vCenter, however.


    $vcenter = "vcenter.domain.com"
    $cred = get-credential
    $licenses = "array","of","license","keys"

    $vc = connect-viserver -server $vcenter -credential $cred

    ## Add Licenses if not already added
    $LicenseManager = get-view ($vc.ExtensionData.content.LicenseManager)
    $existinglicenses = $LicenseManager.licenses.licensekey
    $licensestoadd = $licenses | where-object {$_ -notin $existinglicenses}
    foreach ($license in $licensestoadd)
    write-host"Adding license"+$license

    ## Assign vCenter license to this server
    $majorversion = $vc.version.split(".")[0]
    $vcenterlicense = ($LicenseManager.licenses | where {$_.name -like "*vCenter*" -and $_.name -like "*$majorversion*"} | select -first 1).licensekey ## Select a single vCenter license
    $LicenseAssignmentManager = get-view ($LicenseManager.licenseAssignmentManager)
  • Avatar160.e35e46fe62a53e488ef9451dd1d3432e