Hi all,
Need help to create a script for fetching over allocated license from a vcenter.
I have written a script, which gives the total number of CPU unallocated/overallocated. but its not meeting the actual requirement.
==========================
$ServiceInstance = Get-View ServiceInstance
# Fetches Total license Enterprise plus license count
$LicenseTotal = (Get-View ($ServiceInstance | Select -First 1).Content.LicenseManager | select -ExpandProperty licenses | ? {$_.Name -match "VMware vsphere 5 Enterprise Plus"} | select Total | Measure-Object -Property Total -sum).Sum
# Fetches Total Physical CPU cores in the vcenter.
$CPUTotal = (Get-VMHost | Get-View | Select -ExpandProperty Hardware | Select -ExpandProperty CpuInfo | Measure-Object -Property NumCpuPackages -Sum).Sum
Write-host "License Total is $LicenseTotal"
Write-host "CPU Total is $CPUTotal"
$diff = [int]$LicenseTotal - [int]$CPUTotal
if ($LicenseTotal -gt $CPUtotal)
{
"We have $diff number of free License available"
}
elseif ($LicenseTotal.tovalue -eq $CPUtotal.tovalue)
{
"All the License are assigned"
}
else
{
"$diff *-1 number of license required to make it compliant"
}
# Fetches Total
Get-View ($ServiceInstance | Select -First 1).Content.LicenseManager | select -ExpandProperty licenses | ? {$_.Name -match "Evaluation"} | select LicenseKey, EditionKey,Name,Used,Total| ft -autosize
=======================================
Need output something as below.
S.NO | License Key | Allocation status |
---|---|---|
1 | xxy-xx-xx-exx | 2 CPUs license overallocated |
2 | xxx-xx-xx-xx | 2 CPUs license free |
Though not exactly, it will be useful if I could get output similar to above.
Only overallocated and underallocated License information is required.
Any solution for my query please...
You mean something like this ?
$si = Get-View ServiceInstance | Select -First 1
$licMgr = Get-View $si.Content.LicenseManager
$i = 0
$licMgr.Licenses | where{$_.Name -eq 'VMware vSphere 5 Enterprise Plus'} | %{
[pscustomobject]@{
'S.No' = $i
'License Key' = $_.LicenseKey
'Allocation Status' = &{
if($_.Used -gt $_.Total){
"$($_.Used - $_.Total) CPU license overallocated"
}
else{
"$($_.Total - $_.Used) CPU license free"
}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, Now i wish to check whether
1) a specific license is being used in different vcenters and if used it needs to be reported.
2) License is overutilized than its capacity.
Can you please help on this..
Thanks in advance.
How do you know which vCenters to connect to ?
Are they defined somewhere ?
Are you running in "multiple" or "single" mode ?
You can connect to each vCenter in turn, collect the information from the script above and store it in an array, and then check if a specific license is already used.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1) How do you know which vCenters to connect to ?
We have 6 vcenters and this script needs to check by connecting to all vcenter servers.
2) Are they defined somewhere ?
Should be defined so that before the script starts execution, it will be connected to all the vcenters.
3) Are you running in "multiple" or "single" mode ?
They are all single vcenters, not in linked mode.