PowerCLI

 View Only
  • 1.  Fetch ESXi license name & expiration date with PowerCLI

    Posted Jul 13, 2018 12:16 PM

    Hi folks,

    i have a simple PowerShell inventory script for our ESXi servers and i would like to integrate two additional items:

    License type (Standard, Enterprise, Enterprise Plus)

    License expiration date.

    Does anybody have an advice how to obtain this information with my script below?

    The script looks like follows:

    Get-View -ViewType HostSystem  |

    select Name,

        @{N='Cluster';E={

          $parent = Get-View -Id $_.Parent -Property Name,Parent

          While ($parent -isnot [VMware.Vim.ClusterComputeResource] -and $parent.Parent){

            $parent = Get-View -Id $parent.Parent -Property Name,Parent

          }

          if($parent -is [VMware.Vim.ClusterComputeResource]){

            $parent.Name}}},

    @{N="Type";E={$_.Hardware.SystemInfo.Vendor+ " " + $_.Hardware.SystemInfo.Model}},

    @{N="BIOS version"; E={$_.Hardware.BiosInfo.BiosVersion}},

    @{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}},

    @{N='Product';E={$_.Config.Product.FullName}},

    @{N='Build';E={$_.Config.Product.Build}}| export-csv -NoTypeInformation -Path C:\temp\report_esxihosts.csv

    The script's output so far is a CSV with hostname, cluster, hardware & BIOS information, product name and build number.

    I am not sure whether i can retrieve the addional information with the "Get-View" pipe as well or if i have to build an entirely new loop statement for this ( i am a PowerShell newbie, i must admit).

    Thanks in advance!

    Karsten



  • 2.  RE: Fetch ESXi license name & expiration date with PowerCLI

    Posted Jul 13, 2018 01:08 PM

    Try like this.

    Note that LicenseExpiration will only show a value when there is an expiration date on the license.

    $LicenseManager= Get-view LicenseManager

    $LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

    Get-View -ViewType HostSystem  |

    select Name,

        @{N='Cluster';E={

          $parent = Get-View -Id $_.Parent -Property Name,Parent

          While ($parent -isnot [VMware.Vim.ClusterComputeResource] -and $parent.Parent){

            $parent = Get-View -Id $parent.Parent -Property Name,Parent

          }

          if($parent -is [VMware.Vim.ClusterComputeResource]){

            $parent.Name}}},

    @{N="Type";E={$_.Hardware.SystemInfo.Vendor+ " " + $_.Hardware.SystemInfo.Model}},

    @{N="BIOS version"; E={$_.Hardware.BiosInfo.BiosVersion}},

    @{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}},

    @{N='Product';E={$_.Config.Product.FullName}},

    @{N='Build';E={$_.Config.Product.Build}},

    @{N='LicenseType';E={

        $script:licInfo = $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,@($_.MoRef.Value))

        $licInfo.AssignedLicense.Name

    }},

    @{N='LicenseExpiration';E={$script:licInfo.Properties | where{$_.Key -eq 'expirationDate'} | select -ExpandProperty Value}} |

    Export-Csv -NoTypeInformation -Path C:\temp\report_esxihosts.csv



  • 3.  RE: Fetch ESXi license name & expiration date with PowerCLI

    Posted Jul 13, 2018 01:55 PM

    LucD, thank you very much so far!

    Of course, you are perfectly right that expiration dates are only available with expiring licenses ;-)

    With your suggestion, i am getting in fact the additional information on the license type.

    But i also have indeed expiring licenses (type "Evaluation Mode"), and in these cases, the expiration date is still an empty field in the output file.

    It seems that the licInfo script does not get the proper input values from the Get-View pipe.

    Cheers

    Karsten



  • 4.  RE: Fetch ESXi license name & expiration date with PowerCLI

    Posted Jul 13, 2018 01:58 PM

    To confirm, you do you see the expiration dates for those licenses when you look via the Web Client?

    And which vSphere version are you using?



  • 5.  RE: Fetch ESXi license name & expiration date with PowerCLI

    Posted Jul 13, 2018 02:35 PM

    See attached picture, that's what i'm seeing in vSphere client.

    This environment is vSphere 5.5, the vCenter version is 5.5 Update 3b, build 3252642.

    Cheers,

    Karsten



  • 6.  RE: Fetch ESXi license name & expiration date with PowerCLI

    Posted Jul 13, 2018 04:13 PM

    Ok, try this variation

    $LicenseManager= Get-view LicenseManager

    $LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

    Get-View -ViewType HostSystem  |

    select Name,

        @{N='Cluster';E={

          $parent = Get-View -Id $_.Parent -Property Name,Parent

          While ($parent -isnot [VMware.Vim.ClusterComputeResource] -and $parent.Parent){

            $parent = Get-View -Id $parent.Parent -Property Name,Parent

          }

          if($parent -is [VMware.Vim.ClusterComputeResource]){

            $parent.Name}}},

    @{N="Type";E={$_.Hardware.SystemInfo.Vendor+ " " + $_.Hardware.SystemInfo.Model}},

    @{N="BIOS version"; E={$_.Hardware.BiosInfo.BiosVersion}},

    @{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}},

    @{N='Product';E={$_.Config.Product.FullName}},

    @{N='Build';E={$_.Config.Product.Build}},

    @{N='LicenseType';E={

        $script:licInfo = $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,@($_.MoRef.Value))

        $Script:licInfo.AssignedLicense.Name

    }},

    @{N='LicenseExpiration';E={

        $lic = $LicenseManager.Licenses | where{$_.LicenseKey -eq $script:licInfo.assignedlicense.Licensekey}

        $lic.Properties.GetEnumerator() | where{$_.Key -eq 'expirationDate'} | select -ExpandProperty Value}} |

    Export-Csv -NoTypeInformation -Path C:\temp\report_esxihosts.csv