Public/Get-AnyStackLicenseUsage.ps1
|
function Get-AnyStackLicenseUsage { <# .SYNOPSIS Get-AnyStackLicenseUsage - A VMWare admin utility. .DESCRIPTION AnyStack.vSphere Extension. Autogenerated for VMWare admin daily operations. .INPUTS VMware.VimAutomation.Types.VIServer. Accepts a connected VIServer object via pipeline. .OUTPUTS PSCustomObject. Returns a result object with Timestamp, Status, and relevant data fields. .LINK https://github.com/eblackrps/AnyStack #> [CmdletBinding(SupportsShouldProcess=$false)] [OutputType([PSCustomObject])] param( [Parameter(Mandatory=$true, ValueFromPipeline=$true)] [ValidateNotNull()] [VMware.VimAutomation.Types.VIServer]$Server ) begin { $ErrorActionPreference = 'Stop' } process { try { Write-Verbose "Fetching License Manager on $($Server.Name)..." $licenseManager = Invoke-AnyStackWithRetry -ScriptBlock { Get-View -Server $Server -Id 'LicenseManager' -Property Licenses } if ($null -eq $licenseManager -or $null -eq $licenseManager.Licenses) { Write-Output ([PSCustomObject]@{ Timestamp = (Get-Date) Status = 'No Licenses Found' Server = $Server.Name }) return } foreach ($lic in $licenseManager.Licenses) { [PSCustomObject]@{ Timestamp = (Get-Date) Status = 'Success' Server = $Server.Name LicenseName = $lic.Name LicenseKey = $lic.LicenseKey Total = $lic.Total Used = $lic.Used IsOverused = if ($lic.Total -gt 0) { $lic.Used -gt $lic.Total } else { $false } } } } catch { Write-Error "Failed to fetch license usage: $($_.Exception.Message)" } } } |