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-
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
Have a look at Re: Fetch ESXi license name & expiration date with... - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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!
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
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
}
}
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
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
That means there are entries where there is no expiration date
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
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
It should look like this
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot LucD, it worked, I was pasting to single line.
Thanks again for all your help.
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
You are importing the same file twice
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc, Can you fix the script, I couldnt find where its importing twice.
You are importing the same CSV in $html and $html2
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Before html conversion also ie in raw output Iam seeing double entries.