So I was asked how to audit the VMware license in use vs portal? Meaning what we have vs what VMWare portal says we have vs what are we using. License is a big cost for most. For me I was thinking for sure there is a tool to do a compare, hmmm not that I can find. Sure you can look in your VMware portal to see what you have paid for. However if you are in the middle of a migration/upgrade it could become a mess to see what you have and how much you have paid for. So the fun begins…
This is a very large organization with many different levels of license as well as versions. At that point I was asking if there’s a tool to compare what are allotted vs used vs portal. As you know license can be a mess to maintain but surely there’s a tool to do an audit, well not so fast. I did search the web however i did not see what I was looking for, however I was thinking, surely someone has done this. So I turned to my social media friends for help. I put out a twitt to ask about a script to put this information. Sure enough some folks started to point me to scripting, and someone had one…. Thanks Jonathan Meed.
Requirement is to gather the following:
· Hostname
· License key assigned to the host
· Name of the VC managing the host
· License type
· Flexibility to collect the information for multiple Virtual Centers
So I got a script from Jonathan and massaged it some however I couldn’t get it to do what we needed. This was on me as I was trying to understand each piece of the script. Great Job Jonathan!
So I did a little reading:
API - https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.LicenseManager.html
Understanding ‘Functions’ - http://www.thomas-franke.net/including-scripts-functions-modules/
At this point I decided to just create a script. I asked a friend Matt Derk for some help, he knows scripting pretty good. In any case here is what we came up with and it works,,,, yay
Disclaimer – We tested against VC 5.5
First set the script to collect data from multiple virtual centers:
I saw an error at first so we worked through this to stop the prompting for invalid cert.
# Set to multiple VC Mode
if(((Get-PowerCLIConfiguration).DefaultVIServerMode) -ne "Multiple") {
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
}
Then we wanted to allow for inputting multiple hosts:
#Define VC hosts – IPs or FQDN
$VChosts = @(
"VC1.ron.com",
"VC1.ron.com",
"VC3.ron.com"
);
Write-Host "Connecting to VC Server(s)"
Then connect to the hosts: We didn’t really want to prompt so the script will use the session you are logged in with. If you want to use different creds, right click and choose ‘Run As’.
Connect-VIServer -Server $VChosts
Then we need to define some variables for the data we want to grab
#Define variables for license and host functions
#API - https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.LicenseManager.html
$servInst = Get-View ServiceInstance
$licMgr = Get-View $servInst.Content.licenseManager
$licAssignMgr = Get-View $licMgr.licenseAssignmentManager
Now let’s throw in a function to do this work:
function Get-VMHostId($Name)
{
$vmhost = Get-VMHost $Name | Get-View
return $vmhost.Config.Host.Value
}
function Get-License($VMHostId)
{
$details = @()
$detail = "" |select LicenseKey,LicenseType,Host,VC,Total,Used,ExpirationDate
$license = $licAssignMgr.QueryAssignedLicenses($VMHostId)
$license = $license.GetValue(0)
$detail.VC = ([Uri]$licAssignMgr.Client.ServiceUrl).Host
$detail.Host = $license.EntityDisplayName
$detail.LicenseKey = $license.AssignedLicense.LicenseKey
$detail.LicenseType = $license.AssignedLicense.Name
$detail.Total = $license.AssignedLicense.Total
$detail.Used = $license.AssignedLicense.Used
$details += $detail
return $details
}
Now run this against all hosts and puke out the data to a file. The script is setup to create the path/folders if not there.
# Run Query Against All Hosts
$vmhosts = Get-VMHost
$details = @()
foreach ($vmhost in $vmhosts) {
$vmhostname = Get-VMHostId $vmhost.name
$detail = Get-License $vmhostname
$details += $detail
}
$details
if(!(Test-Path -Path C:\Temp )){New-Item -ItemType directory -Path C:\Temp}
write-host "output being save to C:\Temp\Host-Licenseinfo.csv"
$details | Export-Csv -NoTypeInformation C:\Temp\Host-Licenseinfo.csv
I can assure you I’m no pro at this but hey it works…. J However it seems that the “expire date” is in a different area and couldn’t get it to work within one script so we created second one to grab that. I know it’s not ideal but a manual combine is better than none.
Sample output; now you can sort and do all kinds of things with the data.

I am sure others can make these better. Thanks for reading and happy auditing your license.
Thanks Matt & Jonathan for your time and consideration.
Download script: Licenseinfo-01.txt