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-
I get the error msg as below:
Connect-VIServer : Cannot validate argument on parameter 'Server'. The argument is null or empty. Provide an argument that is not null or empty, and then
try the command again.
At line:5 char:26
+ Connect-VIserver -Server $vcservers -User $user -Password $password
+ ~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Connect-VIServer], ParameterBindingValidationException
Then you have probably more than 1 connection open.
Check what is in $global:defaultVIServers
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Your script says
Connect-VIserver -Server $vc -User $user -Password $password
Why do you use $vcservers now?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Luc
Iam seeing couple of issues in the outcome of this script, few values doesnt corelate with actual data, specifically on license expiration date and entity display name for few line items.
vcenter actual expiration date for vcenter vc01 and vc02 is 01/02/2023 but in script output it is showing as 01/03/2023...not sure is there any mis calculation or data fetching is wrong here.
I have enclosed output of this script for your reference, can you please take a look and help to get the issue fixed at the earliest.
Regards
Srinivas
Hope you understood the issue, let me know if not, will try to explain in detail.
Hello Luc
Any update on this.
Hi Luc
Issue is resolved after removing loop for each vcenter. Thanks for your support as always.
Luc, can you help me to get vcenter name for each line item.
foreach ($license in $assignedLicenses)
{
$lic = $license.Group[0]
$licenseObj = [PSCustomObject]@{
vcenter = $licenseManager | Where-Object {$_.Key -eq 'Licensededition'} | Select-Object -ExpandProperty Value
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
DaysToExpiration = &{
$daysExp = $lic.AssignedLicense.Properties | Where-Object { $_.Key -eq 'ExpirationDate' }
if($daysExp -ne $null){
[math]::Round((New-TimeSpan -End $daysExp.Value -Start $date).TotalDays,0)
}
else{'na'}
}
}
$licenseObj
$licenseUsage += $licenseObj
}
#}
Disconnect-viserver -Server * -Force –Confirm:$false
Hi Luc
Can you help with to fix this below script to generate a html output if there is a table content else write "no license due to expire"
$date = GET-DATE
$htmlformat = '<title>Lic_info</title>'
$htmlformat += '<H1>VMware license forecast notification</H1>'
$htmlformat += '<p>The following report was generated on </p>' + "$date"
$htmlformat += '<style type="text/css">'
$htmlformat += 'BODY{background-color:#E5E8E8 ;color:#000000;font-family:Arial Narrow,sans-serif;font-size:12px;}'
$htmlformat += 'TABLE{border-width: 3px;border-style: solid;border-color: black;border-collapse: collapse;}'
$htmlformat += 'TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#FCF3CF}'
$htmlformat += 'TD{border-width: 1px;padding: 6px;border-style: solid;border-color: black;background-color:#CACFD2}'
$htmlformat += '</style>'
$bodyformat = '<h1> VMware Environment </h1>'
$html = Import-Csv -delimiter ',' -Path "F:\\licdetails.txt" | Select EntityDisplayName,Name,LicenseKey,EditionKey,ProductName,ProductVersion,ExpirationDate,DaysToExpiration | Sort-Object DaysToExpiration | where-object {($_.DaysToExpiration -ne "na") } |
if($_.DaysToExpiration -match "^\d+$")
convertTo-Html -Head $htmlformat -Body {} else {Write-Host "<h1>No licenses due to expire</h1>"}
$html | Out-File F:\VMware_Environment_license_notification.html
Invoke-Expression F:\VMware_Environment_license_notification.html