VMware Cloud Community
BCaldwell2
Contributor
Contributor

Retrieve license keys into selection Menu

Is there a way to take the script Alan has provided in the below link and pipe the output into a Selection menu?

I'm working on a build script and would like to display the available licenses in the vCenter to attach to a host. Then make the selection and add the key.

http://blogs.vmware.com/vipowershell/2012/05/retrieving-license-keys-from-multiple-vcenters.html

# Get the license info from each VC in turn    
$vSphereLicInfo = @()     
$ServiceInstance = Get-View ServiceInstance     
Foreach ($LicenseMan in Get-View ($ServiceInstance | Select -First 1).Content.LicenseManager) {     
    Foreach ($License in ($LicenseMan | Select -ExpandProperty Licenses)) {     
        $Details = "" |Select VC, Name, Key, Total, Used, ExpirationDate , Information     
        $Details.VC = ([Uri]$LicenseMan.Client.ServiceUrl).Host     
        $Details.Name= $License.Name     
        $Details.Key= $License.LicenseKey     
        $Details.Total= $License.Total     
        $Details.Used= $License.Used     
        $Details.Information= $License.Labels | Select -expand Value     
         $Details.ExpirationDate = $License.Properties | Where { $_.key -eq  "expirationDate" } | Select -ExpandProperty Value     
        $vSphereLicInfo += $Details     
    }     
}     
$vSphereLicInfo | Format-Table -AutoSize

0 Kudos
1 Reply
LucD
Leadership
Leadership

One option is to create a windows form, display the rows, select one and continue with the selected row.

But that requires quite a number of PowerShell code to implement.

A quick alternative is to use the Out-GridView cmdlet with the Pasthru parameter.

Then you can do

$vSphereLicInfo | Out-GridView -PassThru |  Format-List

and it will display the selected row(s).

You can of course also capture the selected row in a variable and then continue with that variable to set the license.

$license = $vSphereLicInfo | Out-GridView -PassThru


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos