Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Return vSphere licenses from a vCenter Server
function Get-VILicense {
<#
.SYNOPSIS
Return vSphere license deatils from the connected vCenter Server(s)
.DESCRIPTION
Return vSphere license deatils from the connected vCenter Server(s)
.EXAMPLE
Get-VILicense -Verbose
.OUTPUTS
System.Management.Automation.PSCustomObject
.NOTES
--------------------------------
Author: Kevin Kirkpatrick
Email: kevin@nullzero.io
GitHub: https:\GitHub.com\vScripter
Last Updated: 20170921
Last Updated By: K. Kirkpatrick
Last Update Notes:
- Published to GitHub Gist
#>
[cmdletbinding()]
[OutputType([System.Management.Automation.PSCustomObject])]
param ()
BEGIN {
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)] Processing Started"
} # end BEGIN block
PROCESS {
try {
# Using Write-Warning instead of Write-Verbose so that Get-View verbose messages are suppressed
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)] Gathering vSphere license details"
$ServiceInstance = $null
$ServiceInstance = Get-View ServiceInstance
Foreach ($licenseMan in Get-View ($ServiceInstance | Select-Object -First 1).Content.LicenseManager) {
Foreach ($license in $LicenseMan.Licenses) {
[PSCustomObject]@{
VIServer = ([Uri]$LicenseMan.Client.ServiceUrl).Host
Name = $License.Name
Key = $License.LicenseKey
CostUnit = $License.CostUnit
Total = $License.Total
Used = $License.Used
Information = $License.Labels.Value
ExpirationDate = ($License.Properties | Where-Object { $_.key -eq "expirationDate" }).Value
} # end obj
} # end foreach $license
} # end foreach $licenseMan
} catch {
Write-Warning -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)][ERROR] $_"
} # end try/catch
} # end PROCESS block
END {
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)] Processing Complete"
} # end END block
} # function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.