VMware’s licensing is quite flexible, if you have, say 1 10 socket license, you are able to split the license in to blocks so each vSphere instance get’s it’s own dedicated license key. But sometimes you encounter a situation where the people before you just reused licenses, and the vCenters aren’t linked. Because one could’t login to the license portal, and “yeah, I know we bought extra licenses, but I already know this license key, so why bother with another..” As long as you’ve bought all the license keys you need it shouldn’t be to big of a deal. <- This is my guess, I must admit that I've never looked in to the details of the licensing agreements! But in my case I found an enviroment where keys where used in multiple instances. I needed a way to quickly find all keys used, and split them in to groups of the same kind (Enterprise, Enterprise Plus, etc) and calculate if we have over- or under-utilized them.
I've written a script to help me find out. The examples shown are old values, all systems are now fully licensed.
Output of the script: (Summary.txt)
LicenseKey Available Used
---------- --------- ----
AAAAA-AAAAA-AAAAA-AAAAA-AAAAA 48 48
BBBBB-BBBBB-BBBBB-BBBBB-BBBBB 1 1
CCCCC-CCCCC-CCCCC-CCCCC-CCCCC 225 279
00000-00000-00000-00000-00000 0 4
DDDDD-DDDDD-DDDDD-DDDDD-DDDDD 1 1
EEEEE-EEEEE-EEEEE-EEEEE-EEEEE 1 2
FFFFF-FFFFF-FFFFF-FFFFF-FFFFF 1 2
GGGGG-GGGGG-GGGGG-GGGGG-GGGGG 16 8
HHHHH-HHHHH-HHHHH-HHHHH-HHHHH 8 8
IIIII-IIIII-IIIII-IIIII-IIIII 12 46
JJJJJ-JJJJJ-JJJJJ-JJJJJ-JJJJJ 10000 0
KKKKK-KKKKK-KKKKK-KKKKK-KKKKK 4 4
LLLLL-LLLLL-LLLLL-LLLLL-LLLLL 1 1
MMMMM-MMMMM-MMMMM-MMMMM-MMMMM 12 12
NNNNN-NNNNN-NNNNN-NNNNN-NNNNN 175 168
OOOOO-OOOOO-OOOOO-OOOOO-OOOOO 1 1
PPPPP-PPPPP-PPPPP-PPPPP-PPPPP 20 0
QQQQQ-QQQQQ-QQQQQ-QQQQQ-QQQQQ 1 1
Product Available Used Adheres
------- --------- ---- -------
vCenter Operations Management Suite Enterprise Edition 5.6 10175 168 True
vCenter Server 5 Standard 7 9 False
VMware vSphere 5 Enterprise Plus 120 126 False
Product Evaluation 0 4 False
vCenter Operations Management Suite Standard Edition 5.6 225 279 False
The fun starts with the IIIII-IIIII-IIIII-IIIII-IIIII license. It was used on 46 sockets, while it only allows for 12. But when we looked at the type of license it’s only over utilized by 6 sockets.
The complete list of licenses added to each vCenter: (VMwareLicenses.csv)
VC,Name,Key,Total,Used,ExpirationDate,Information
10.18.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,0,,
10.10.1.1,vCenter Server 5 Standard,AAAAA-AAAAA-AAAAA-AAAAA-AAAAA,1,1,,
10.18.1.1,vCenter Server 5 Standard,BBBBB-BBBBB-BBBBB-BBBBB-BBBBB,1,1,,
10.18.1.1,VMware vSphere 5 Enterprise Plus,CCCCC-CCCCC-CCCCC-CCCCC-CCCCC,12,10,,
10.11.1.1,vCenter Operations Management Suite Standard Edition 5.6,DDDDD-DDDDD-DDDDD-DDDDD-DDDDD,225,57,,vCOPS Standard
10.11.1.1,vCenter Server 5 Standard,EEEEE-EEEEE-EEEEE-EEEEE-EEEEE,1,1,,
10.10.1.1,VMware vSphere 5 Enterprise Plus,CCCCC-CCCCC-CCCCC-CCCCC-CCCCC,12,12,,
10.10.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,1,,
10.12.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,0,,
10.13.1.1,VMware vSphere 5 Enterprise Plus,FFFFF-FFFFF-FFFFF-FFFFF-FFFFF,12,12,,vSphere 5 Enterprise Plus
10.12.1.1,VMware vSphere 5 Enterprise Plus,CCCCC-CCCCC-CCCCC-CCCCC-CCCCC,12,6,,
10.12.1.1,vCenter Server 5 Standard,EEEEE-EEEEE-EEEEE-EEEEE-EEEEE,1,1,,
10.18.1.1,vCenter Operations Management Suite Standard Edition 5.6,DDDDD-DDDDD-DDDDD-DDDDD-DDDDD,225,222,,vCops Standard
10.18.1.1,VMware vSphere 5 Enterprise Plus,GGGGG-GGGGG-GGGGG-GGGGG-GGGGG,16,8,,
10.13.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,1,,
10.13.1.1,vCenter Server 5 Standard,HHHHH-HHHHH-HHHHH-HHHHH-HHHHH,1,1,,
10.11.1.1,VMware vSphere 5 Enterprise Plus,IIIII-IIIII-IIIII-IIIII-IIIII,8,8,,
10.14.1.1,vCenter Operations Management Suite Enterprise Edition 5.6,JJJJJ-JJJJJ-JJJJJ-JJJJJ-JJJJJ,10000,0,VMware.Vim.KeyAnyValue,
10.14.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,1,,
10.14.1.1,VMware vSphere 5 Enterprise Plus,KKKKK-KKKKK-KKKKK-KKKKK-KKKKK,48,48,,
10.14.1.1,vCenter Operations Management Suite Enterprise Edition 5.6,LLLLL-LLLLL-LLLLL-LLLLL-LLLLL,175,168,,
10.15.1.1,vCenter Server 5 Standard,MMMMM-MMMMM-MMMMM-MMMMM-MMMMM,1,1,,
10.15.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,0,,
10.14.1.1,vCenter Server 5 Standard,NNNNN-NNNNN-NNNNN-NNNNN-NNNNN,1,1,,
10.15.1.1,VMware vSphere 5 Enterprise Plus,OOOOO-OOOOO-OOOOO-OOOOO-OOOOO,4,4,,
10.16.1.1,VMware vSphere 5 Enterprise Plus,CCCCC-CCCCC-CCCCC-CCCCC-CCCCC,12,6,,
10.16.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,0,,
10.11.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,0,,
10.16.1.1,vCenter Server 5 Standard,PPPPP-PPPPP-PPPPP-PPPPP-PPPPP,1,1,,
10.17.1.1,Product Evaluation,00000-00000-00000-00000-00000,0,1,,
10.14.1.1,VMware vSphere 5 Enterprise Plus,QQQQQ-QQQQQ-QQQQQ-QQQQQ-QQQQQ,20,0,,
10.17.1.1,VMware vSphere 5 Enterprise Plus,CCCCC-CCCCC-CCCCC-CCCCC-CCCCC,12,12,,
10.17.1.1,vCenter Server 5 Standard,PPPPP-PPPPP-PPPPP-PPPPP-PPPPP,1,1,,
And finally the script:
Function Get-vCenterCredential ($vCenterDomain, $UserName) {
$CredentialsFile = $vCenterDomain+".cred"
$UPN = $UserName+"@"+$vCenterDomain
$Password = Get-Content C:\Scripts\Creds\$CredentialsFile | ConvertTo-SecureString
$Creds = New-Object System.Management.Automation.PSCredential($UPN,$Password)
$Creds
}
Function Make-Dir ($Directory) {
If (!(Test-Path $OutputPath)) {
New-Item $OutputPath -ItemType Directory | Out-Null
}
}
$UserName = "vmninja"
$Creds = $Null
$AllVMs=@{}
Add-PSSnapin VMware.VimAutomation.Core
$vCenters=Import-Csv C:\Scripts\vCenters.csv -Delimiter ";"
$Date=Get-Date -Format yyyyMMdd
$vCenters|ForEach-Object {
$Domain = $_.UserDomain
$vCenterServer = $_.vCenterIP
$OutputPath = "C:\Scripts\Output\LicenseInfo\"+$Date.ToString()
Make-Dir $OutputPath
$Creds = Get-vCenterCredential -vCenterDomain $Domain -UserName $UserName
$VIConnection = Connect-VIServer $vCenterServer -Credential $Creds
}
$vSphereLicInfo = @()
$ServiceInstance = Get-View ServiceInstance
Foreach ($LicenseMan in Get-View ($ServiceInstance | Select-Object -First 1).Content.LicenseManager) {
Foreach ($License in ($LicenseMan | Select -ExpandProperty Licenses)) {
$Details = "" | Select VC, Name, Key, Total, Used, ExpirationDate, Information
$Details.VC = ([Uri]$LicenseMan.Client.ServiceUrl).Host
$Details.Name = $License.Name
$Details.Key = $License.LicenseKey
$Details.Total = $License.Total
$Details.Used = $License.Used
$Details.Information = $License.Labels | Select -ExpandProperty Value
$Details.ExpirationDate = $License.Properties | Where-Object {$_.Key -eq "expirationDate"} | Select-Object -ExpandProperty Value
$vSphereLicInfo += $Details
}
}
$vSphereLicInfo | Sort-Object | Export-Csv -NoTypeInformation -Path $OutputPath\VMwareLicenses.csv
$vSphereLicInfo | Format-Table -AutoSize
$AvailableLicenses=$vSphereLicInfo | Select-Object Key, Total -Unique
$UsedLicenses=$vSphereLicInfo | Select-Object Key, Used
$DataSet=$UsedLicenses|Group-Object -Property key -AsHashTable
$tab=@{}
$DataSet.Keys | % {$tab += @{$_ = ($DataSet[$_]|Measure-Object -Property Used -Sum)}}
$Licenses = @()
$tab.Keys | % {
[string]$CurrentKey=$_
$Avail=$AvailableLicenses|Where-Object {$_.key -match $CurrentKey}|Select-Object $_.Total
$Lic = "" | Select LicenseKey, Available, Used
$Lic.LicenseKey = $CurrentKey
$Lic.Available = $Avail.Total
$Lic.Used = $tab[$CurrentKey].sum
$Licenses += $Lic
}
$Licenses | ft -AutoSize | Out-File $OutputPath\Summary.txt
$AvailableLicenses=$vSphereLicInfo | Select-Object Name, Key, Total -Unique
$UsedLicenses=$vSphereLicInfo | Select-Object Name, Key, Used
$DataSetAvail=$AvailableLicenses|Group-Object -Property Name -AsHashTable
$tabAvail=@{}
$DataSetAvail.Keys | % {$tabAvail += @{$_ = ($DataSetAvail[$_]|Measure-Object -Property Total -Sum)}}
$DataSetUsed=$UsedLicenses|Group-Object -Property Name -AsHashTable
$tabUsed=@{}
$DataSetUsed.Keys | % {$tabUsed += @{$_ = ($DataSetUsed[$_]|Measure-Object -Property Used -Sum)}}
$Licenses = @()
$LicInUse = @()
$LicInStock = @()
$tabUsed.Keys | % {
$Product=$_
$LicUsed=$tabUsed[$Product].sum
$LU = "" | Select Product, UsedLicenses
$LU.Product = $Product
$LU.UsedLicenses = $LicUsed
$LicInUse += $LU
Write-Host Used: $Product`t $LicUsed
}
$tabAvail.Keys | % {
$Product=$_
$LicAvail=$tabAvail[$Product].sum
$LA = "" | Select Product, AvailableLicenses
$LA.Product = $Product
$LA.AvailableLicenses = $LicAvail
$LicInStock += $LA
}
$LicenseOverview=@()
$LicInUse | ForEach-Object {
[string]$Product = $_.Product
[int]$Used = $_.UsedLicenses
$Available = $LicInStock | Where-Object {$_.Product -eq $Product} | Select-Object -ExpandProperty AvailableLicenses
If ($Used -le $Available){
$Adheres=$true
}
Else {
$Adheres=$false
}
$LO = "" | Select Product, Available, Used, Adheres
$LO.Product = $Product
$LO.Available = $Available
$LO.Used = $Used
$LO.Adheres = $Adheres
$LicenseOverview += $LO
}
$LicenseOverview | ft -AutoSize | Out-File $OutputPath\Summary.txt -Append
To save the credentials used by the script, I’ve used the following script:
The user that saves the credentials is the only one who can decrypt, so make sure you run the script with the correct credentials.
$file=$null
$vCenterDomain=Read-Host "Please enter the userdomain: "
$File="C:\Scripts\Creds\"+$vCenterDomain.ToUpper()+".cred"
$Credential = Get-Credential
$Credential.Password | ConvertFrom-SecureString | Set-Content $File