VMware Cloud Community
PGuibordCharter
Contributor
Contributor
Jump to solution

Audit Licenses

I am trying to get license details from my vCenter, specifically when they expire.  I can get the edition, total used, etc., however I cannot seem to find the property/key for the license expire value.  Here is what I have so far-

 

ForEach ($Licenses in (Get-View $Global:DefaultVIServer.ExtensionData.Content.LicenseManager).Licenses){
 
ForEach ($Property in $Licenses){

$licenseObj = New-Object PSObject

$licenseObj | Add-Member -Name "vCenter Name" -MemberType NoteProperty -Value $Global:DefaultVIServer.Name
$licenseObj | Add-Member -Name "License Name" -MemberType NoteProperty -Value $Property.Name
$licenseObj | Add-Member -Name "License Key" -MemberType NoteProperty -Value $Property.LicenseKey
#$licenseObj | Add-Member -Name "Expiration Date" -MemberType NoteProperty -Value $Property.?????

$licenseObj
}
}
 
 
Commented out the line I am missing
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, then try like this

$LicenseManager= Get-view LicenseManager
$LicenseManager.Licenses | where{$_.Total -ne 0} |
Select Name,LicenseKey,Used,Total,
  @{N='ExpirationDate';E={$_.Properties | where{$_.Key -eq 'expirationDate'} | Select -ExpandProperty Value}}


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

View solution in original post

0 Kudos
28 Replies
LucD
Leadership
Leadership
Jump to solution

0 Kudos
PGuibordCharter
Contributor
Contributor
Jump to solution

Thank you sir- appreciate the help!

I am pulling this detail from vCenter, about each license that is installed.  Not the individual hosts but rather vCenter version/license key, vSAN version/license key, etc. for each product registered in vCenter.  The column I can't get details on is the Expired check box.  I know there are some vCenter's that have a 60 day or 90 key or even one that expires every year!  Is there a way to expose this value?

Thanks!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, then try like this

$LicenseManager= Get-view LicenseManager
$LicenseManager.Licenses | where{$_.Total -ne 0} |
Select Name,LicenseKey,Used,Total,
  @{N='ExpirationDate';E={$_.Properties | where{$_.Key -eq 'expirationDate'} | Select -ExpandProperty Value}}


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

0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Hi

Can anyone help me on this script to include license remaining days to expire in the below script, this is bit urgent.

ForEach ($vc in $vcservers){
Connect-VIserver -Server $vc -User $user -Password $password
$licenseManager = Get-View $Global:DefaultVIServers.ExtensionData.content.LicenseManager
$licenseAssignmentManager = Get-View $LicenseManager.licenseAssignmentManager
$assignedLicenses = $licenseAssignmentManager.QueryAssignedLicenses($global.defaultviservers.instanceuuid) | Group-Object -Property EntityDisplayName

foreach ($license in $assignedLicenses)
{
#$vCenterName = ([System.uri]$license.Client.ServiceUrl).Host
$lic = $license.Group[0]
$licenseObj = [PSCustomObject]@{
vcenter = $vc
EntityDisplayName = $lic.EntityDisplayName
Name = $lic.AssignedLicense.Name
LicenseKey = $lic.AssignedLicense.LicenseKey
EditionKey = $lic.AssignedLicense.EditionKey
ProductName = $lic.AssignedLicense.Properties | Where-Object {$_.Key -eq 'ProductName'} | Select-Object -ExpandProperty Value

ProductVersion = $lic.AssignedLicense.Properties | Where-Object {$_.Key -eq 'ProductVersion'} | Select-Object -ExpandProperty Value
ExpirationDate = $lic.AssignedLicense.Properties | Where-Object {$_.Key -eq 'ExpirationDate'} | Select-Object -ExpandProperty Value
ExpirationHours = $lic.AssignedLicense.Properties | Where-Object {$_.Key -eq 'expirationHours'} | Select-Object -ExpandProperty Value
ExpirationMins= $lic.AssignedLicense.Properties | Where-Object {$_.Key -eq 'expirationMinutes'} | Select-Object -ExpandProperty Value

}
$licenseObj
$licenseUsage += $licenseObj
}
}

Tags (1)
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Add this property

            DaysToExpiration = [math]::Round((New-TimeSpan -End ($lic.AssignedLicense.Properties | Where-Object { $_.Key -eq 'ExpirationDate' }).Value -Start $now).TotalDays,0)


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

0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Hi Luc

I get this error msg as below when i execute

New-TimeSpan : Cannot bind parameter 'End' to the target. Exception setting "End": "Cannot convert null to type "System.DateTime"."
At S:\srini\scripts\licdetailextract_final.ps1:29 char:61
+ ... meSpan -End ($lic.AssignedLicense.Properties | Where-Object { $_.Key ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [New-TimeSpan], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewTimeSpanCommand

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That means there are entries where there is no expiration date


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

0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Hi LucD

Thanks for your response, I really appreciate it.

Please find the enclosed script output in this post for your references, there are no values in expiration date except few.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

To cope with missing values, you could do

            DaysToExpiration = &{
                $daysExp = $lic.AssignedLicense.Properties | Where-Object { $_.Key -eq 'ExpirationDate' }
                if($daysExp -ne $null){
                    [math]::Round((New-TimeSpan -End $daysExp.Value -Start $now).TotalDays,0)
                }
                else{'na'}
            }


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

0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Nope, it didnt work, below is the error message:

Where-Object : A positional parameter cannot be found that accepts argument 'if'.
At line:30 char:76
+ ... roperties | Where-Object { $_.Key -eq 'ExpirationDate' } if($daysExp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WhereObjectCommand

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looks like you are missing some CR-LF in the copy-paste.
That If should start on a new line


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It should look like this
lines.jpg


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

0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Thanks a lot LucD, it worked, I was pasting to single line.

Thanks again for all your help.

Tags (1)
0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

 

 

Tags (1)
0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Hi Luc

For some reason, Iam seeing 2 entries for each line, can you check on the script and let me know if you see any findings.

Srinivas

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are importing the same file twice


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

0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Luc, Can you fix the script, I couldnt find where its importing twice.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are importing the same CSV in $html and $html2


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

0 Kudos
vsrini_blr
Contributor
Contributor
Jump to solution

Hi,

Before html conversion also ie in raw output Iam seeing double entries.

0 Kudos