###License Auditor### ###By Matt Derk & vTwindude### # Set to multiple VC Mode if(((Get-PowerCLIConfiguration).DefaultVIServerMode) -ne "Multiple") { Set-PowerCLIConfiguration -DefaultVIServerMode Multiple | Out-Null } #Define VC hosts $VChosts = @( "VMVC01", "VMVC02" ); Write-Host "Connecting to VC Server(s)" Connect-VIServer -Server $VChosts #Define variables for license and host functions $servInst = Get-View ServiceInstance $licMgr = Get-View $servInst.Content.licenseManager $licAssignMgr = Get-View $licMgr.licenseAssignmentManager 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 } # 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