Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Powercli Get vCenter licenses information

Recently I was testing vCenter and Esxi 7 - vSphere suite for my new project, I periodically ask my subordinate team to review and collect the licenses information to know and forecast licensing needs. To use this script first I fill and run information accordingly. (Temporarily remove/unload Hyper-V module (not uninstalling) so VMware PowerCLI commands won't conflict), Load latest PowerCLI module. In the last login multiple vCenter at once.

Powercli Get vCenter licenses information
Powercli Get vCenter assigned licenses report

#1: Unload Hyper-V module
Remove-Module Hyper-V

#2: Load Powercli Module
Import-Module VMware.PowerCLI

#3: Connect to multiple vCenter (Change servername, user and password accordingly)
Connect-VIserver -Server 192.168.34.20 -User administrator@vsphere.local -Password passward
Connect-VIserver -Server marvel.vcloud-lab.com -User administrator@vsphere.local -Password passward

After running the script it give me complete list of information. If the output need to be in csv file use as below.

Get-vSphereLicenseInfo.ps1 | Export-Csv c:\licdata.csv

Vmware vsphere vsan esxi 7 licenses get-view licensemanager free licesense key vcenter administration, Enterprise plus with add-on for kubernetes virtualcenter server esxi server evaluation free crack.png

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#requires -version 4
<#
.SYNOPSIS
    Get complete license information from vCenter Server
.DESCRIPTION
    The Get-vSphereLicensesInfo.ps1 gets license information from vCenter Server. License information ie: vCenter, Esxi, vSAN etc.
.PARAMETER File
    Prompts you for csv file location.
    
.INPUTS
    VMware.Vim.LicenseManager
    VMware.Vim.LicenseManagerLicenseInfo
.OUTPUTS
    VMware.Vim.LicenseManagerLicenseInfo
.NOTES
  Version:        1.0
  Author:         Kunal Udapi
  Creation Date:  09 May 2020
  Purpose/Change: Gather vCenter Esxi licenses information
  Useful URLs: http://vcloud-lab.com
  Tested on below versions:
    vCenter/Esxi: 7.0
    PowerCLI: 12.0
    PowerShell: 5.1
.EXAMPLE
    Name           : Product Evaluation
    LicenseKey     : 00000-00000-00000-00000-00000
    ExpirationDate : Evaluation
    ProductName    : VMware vSphere 7 Enterprise Plus with Add-on for Kubernetes
    ProductVersion : Evaluation
    EditionKey     : eval
    Total          : Unlimited
    Used           : 2
    CostUnit       : esx.enterprisePlus.cpuPackage
    Labels         : 
    vCenter        : vcsa.vcloud-lab.com

    This script shows information as above information.
#>

<#
Remove-Module Hyper-V
Import-Module VMware.PowerCLI
Connect-VIserver -Server 192.168.34.20 -User administrator@vsphere.local -Password passward
Connect-VIserver -Server marvel.vcloud-lab.com -User administrator@vsphere.local -Password passward
#>

foreach ($licenseManager in (Get-View LicenseManager)) #-Server $vCenter.Name
{
    $vCenterName = ([System.uri]$licenseManager.Client.ServiceUrl).Host
    #($licenseManager.Client.ServiceUrl -split '/')[2]
    foreach ($license in $licenseManager.Licenses)
    {
        $licenseProp = $license.Properties
        $licenseExpiryInfo = $licenseProp | Where-Object {$_.Key -eq 'expirationDate'} | Select-Object -ExpandProperty Value
        if ($license.Name -eq 'Product Evaluation')
        {
            $expirationDate = 'Evaluation'
        } #if ($license.Name -eq 'Product Evaluation')
        elseif ($null -eq $licenseExpiryInfo)
        {
            $expirationDate = 'Never'
        } #elseif ($null -eq $licenseExpiryInfo)
        else
        {
            $expirationDate = $licenseExpiryInfo
        } #else #if ($license.Name -eq 'Product Evaluation')
    
        if ($license.Total -eq 0)
        {
            $totalLicenses = 'Unlimited'
        } #if ($license.Total -eq 0)
        else 
        {
            $totalLicenses = $license.Total
        } #else #if ($license.Total -eq 0)
    
        $licenseObj = New-Object psobject
        $licenseObj | Add-Member -Name Name -MemberType NoteProperty -Value $license.Name
        $licenseObj | Add-Member -Name LicenseKey -MemberType NoteProperty -Value $license.LicenseKey
        $licenseObj | Add-Member -Name ExpirationDate -MemberType NoteProperty -Value $expirationDate
        $licenseObj | Add-Member -Name ProductName -MemberType NoteProperty -Value ($licenseProp | Where-Object {$_.Key -eq 'ProductName'} | Select-Object -ExpandProperty Value)
        $licenseObj | Add-Member -Name ProductVersion -MemberType NoteProperty -Value ($licenseProp | Where-Object {$_.Key -eq 'ProductVersion'} | Select-Object -ExpandProperty Value)
        $licenseObj | Add-Member -Name EditionKey -MemberType NoteProperty -Value $license.EditionKey
        $licenseObj | Add-Member -Name Total -MemberType NoteProperty -Value $totalLicenses
        $licenseObj | Add-Member -Name Used -MemberType NoteProperty -Value $license.Used
        $licenseObj | Add-Member -Name CostUnit -MemberType NoteProperty -Value $license.CostUnit
        $licenseObj | Add-Member -Name Labels -MemberType NoteProperty -Value $license.Labels
        $licenseObj | Add-Member -Name vCenter -MemberType NoteProperty -Value $vCenterName
        $licenseObj
    } #foreach ($license in $licenseManager.Licenses)
} #foreach ($licenseManager in (Get-View LicenseManager)) #-Server $vCenter.Name

This script is available here Get-vSphereLicensesInfo.ps1, you can also download it from github.com.

Useful Information
Resolved syslog error: Call OptionManager.UpdateValues for object ha-adv-options on ESXi failed
Solved: Esxi server cannot joined into active directory domain
Solved Esxi host disconnected evaluation license expired
Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration

Go Back

Comment

Blog Search

Page Views

4127759

Follow me on Blogarama