After I wrote the licensing server post a couple of days back one of my colleagues(Thanks Horst!) was so kind to email me the following script. What it basically does is check every server for the availability of the license source. Of course it can be improved by adding for instance a check to see if the license service is running on the license server and for instance email the results if there’s an error…I will leave that up to the powershell guru’s like mr Renouf. Here’s the script:
# This script checks the availability of the configured license source for all ESX hosts that are managed by a given VC
# The script assumes that there is a user account that has the same password on all hosts
# It is higly recommended to use an account that has a read-only role
# The first credential pop-up is for VC, the second for ESX hosts
connect-viserver <VC>
$vmhosts = Get-VMHost
Disconnect-VIServer -Confirm:$false
$numhosts = $vmhosts.Length
if ($numhosts -eq 0) { exit 1 }
$credential = Get-Credential
$availability = @{}
$badcounter = 0;
$hostcounter = 1
$vmhosts | foreach {
$progress = [int] ($hostcounter * 100 / $numhosts)
Write-Progress “Checking license source availability” “Checking Host” -PercentComplete $progress -CurrentOperation “Checking host $_”
connect-VIServer $_.name -Credential $credential
$svcRef = new-object VMware.Vim.ManagedObjectReference;
$svcRef.Type = “ServiceInstance”;
$svcRef.Value = “ServiceInstance”;
$serviceInstance = get-view $svcRef;
$lic_ref = $serviceInstance.content.licensemanager;
$LM = Get-View $lic_ref;
$available = $LM.SourceAvailable
$availability[$_.Name] = $available
if ($available -eq $false ) { $badcounter++ }
Disconnect-VIServer -Confirm:$false
$hostcounter++
}
Write-Host $badcounter ” Hosts without available license source.”
foreach ($item in $availability.GetEnumerator() )
{
if ($item.value -eq $False ) {Write-Host “Host ” $item.name ” does not have a valid license source” }
}
William says
Something similar using the Perl and the VI Perl Toolkit: http://engr.ucsb.edu/~duonglt/vmware/checkLicenseServer.pl
[vi-admin@vima ~]$ ./checkLicenseServer.pl –server resvc.resnet.ucsb.edu –username primp
Enter password:
License Server available: true
Querying hosts …
All hosts are licensed!
[vi-admin@vima ~]$ ./checkLicenseServer.pl –server reflex.primp-industries.com –username primp
Enter password:
Checking License Server: [email protected]
License Source availability false
License Server is down!
It will first check License Server to ensure it’s running and available and then query each of the host(s) and only print host(s) that do not have a license source available.
–William