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
<# PowerCLI script to create New vCenter License
+++++++++++++++++++++++++++++++++++++++++++++++++
+______ _____ _ _____ +
+| ___ \ / __ \| | |_ _|+
+| |_/ /____ _____ _ __| / \/| | | | +
+| __/ _ \ \ /\ / / _ \ '__| | | | | | +
+| | | (_) \ V V / __/ | | \__/\| |_____| |_ +
+\_| \___/ \_/\_/ \___|_| \____/\_____/\___/ +
+++++++++++++++++++++++++++++++++++++++++++++++++
# New vCenter License (esxi 6.0,6.5,6.7,7.0)
# .\powercli-vCenter-New-License.ps1
#>
#set vCenter credentials
$vCenterServer = "YOU_IP"
$User= "administrator@vsphere.local"
$Password= "YOU_password"
$licenses = "4C418-FD0E0-085E8-U10N4-A2214"
#Convert the password to connect
$EncryptedPassword = ConvertTo-SecureString -String "$Password" -AsPlainText -Force
#Set the credentials or you can alternatively request them using the interactive mode with $Credential = get-credential
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $EncryptedPassword
#Connect to the vCenter
Disconnect-VIServer -confirm:$false -ErrorAction SilentlyContinue
Write-Host "Now connecting to $vCenterServer"
$vCenter = Connect-VIServer -Server $vCenterServer -Credential $Credential
## Add Licenses if not already added
$LicenseManager = get-view ($vCenter.ExtensionData.content.LicenseManager)
$existinglicenses = $LicenseManager.licenses.licensekey
$licensestoadd = $licenses | where-object {$_ -notin $existinglicenses}
foreach ($license in $licensestoadd)
{
Write-Host "AddLicense"+$license
$LicenseManager.AddLicense($license,$null)
}
## Assign vCenter license to this server
$majorversion = $vCenter.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)
$LicenseAssignmentManager.UpdateAssignedLicense($vCenter.InstanceUuid,$License,$Null)
It would be great if we can use this functionality for retrieving license/usage information we can use in license compliancy reports instead of making screenshots. Including VMware products like Horizon View, NSX, VROPS, Loginsight, VRNI, VRA, Appvolumes
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.