getVMwareLicenses.ps1

You are here:
< Back


## getVMwareLicenses.ps1
## Script function: Get VMware licensing information from multiple vCenter Servers
## Author: Erik Hinderer @VMW ehinderer@vmware.com
## Version 1.6
## Set multi-server vCenter Mode
# Adds the base cmdlets
Add-PSSnapin VMware.VimAutomation.Core
$config = Get-PowerCLIConfiguration 
if($config.DefaultVIServerMode -eq "Single"){
    Set-PowerCLIConfiguration -DefaultVIServerMode Multiple
}
## Connect to vCenter Servers
$vclist = @(Read-Host "Enter each vCenter server separated with a comma").split(',') | % {$_.trim()}
"Please enter your vCenter credentials"
$creds = get-credential "root"
connect-viserver -server $vclist -credential $creds -WarningAction 0
$vSphereLicInfo = @()
$ServiceInstance = Get-View ServiceInstance
Foreach ($LicenseMan in Get-View ($ServiceInstance | Select -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 -expand Value
        $Details.ExpirationDate = $License.Properties | Where { $_.key -eq "expirationDate" } | Select -ExpandProperty Value
        $vSphereLicInfo += $Details
    }
}
$vSphereLicInfo | Select-Object VC,Name,Key,Total,Used,ExpirationDate,Information | Export-Csv C:\VMwareLicenses_$vclist.csv -notype
disconnect-viserver * -confirm:$false