Skip to content

Commit 2290774

Browse files
add option for multiple input fields.
1 parent 6f25bd4 commit 2290774

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertExpiringLicenses.ps1

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,45 @@ function Get-CIPPAlertExpiringLicenses {
1111
$TenantFilter
1212
)
1313
try {
14+
# Parse input parameters - default to 30 days if not specified
15+
# Support both old format (direct value) and new format (object with properties)
16+
if ($InputValue -is [hashtable] -or $InputValue -is [PSCustomObject]) {
17+
$DaysThreshold = if ($InputValue.ExpiringLicensesDays) { [int]$InputValue.ExpiringLicensesDays } else { 30 }
18+
$UnassignedOnly = if ($null -ne $InputValue.ExpiringLicensesUnassignedOnly) { [bool]$InputValue.ExpiringLicensesUnassignedOnly } else { $false }
19+
} else {
20+
# Backward compatibility: if InputValue is a simple value, treat it as days threshold
21+
$DaysThreshold = if ($InputValue) { [int]$InputValue } else { 30 }
22+
$UnassignedOnly = $false
23+
}
24+
1425
$AlertData = Get-CIPPLicenseOverview -TenantFilter $TenantFilter | ForEach-Object {
1526
$TermData = $_.TermInfo | ConvertFrom-Json
27+
$UnassignedCount = [int]$_.CountAvailable
28+
29+
# If unassigned only filter is enabled, skip licenses with no unassigned units
30+
if ($UnassignedOnly -and $UnassignedCount -le 0) {
31+
return
32+
}
33+
1634
foreach ($Term in $TermData) {
17-
if ($Term.DaysUntilRenew -lt 30 -and $Term.DaysUntilRenew -gt 0) {
18-
Write-Host "$($_.License) will expire in $($Term.DaysUntilRenew) days. The estimated term is $($Term.Term)"
35+
if ($Term.DaysUntilRenew -lt $DaysThreshold -and $Term.DaysUntilRenew -gt 0) {
36+
$Message = if ($UnassignedOnly) {
37+
"$($_.License) has $UnassignedCount unassigned license(s) expiring in $($Term.DaysUntilRenew) days. The estimated term is $($Term.Term)"
38+
} else {
39+
"$($_.License) will expire in $($Term.DaysUntilRenew) days. The estimated term is $($Term.Term)"
40+
}
41+
42+
Write-Host $Message
1943
[PSCustomObject]@{
20-
Message = "$($_.License) will expire in $($Term.DaysUntilRenew) days. The estimated term is $($Term.Term)"
44+
Message = $Message
2145
License = $_.License
2246
SkuId = $_.skuId
2347
DaysUntilRenew = $Term.DaysUntilRenew
2448
Term = $Term.Term
2549
Status = $Term.Status
2650
TotalLicenses = $Term.TotalLicenses
2751
CountUsed = $_.CountUsed
52+
CountAvailable = $UnassignedCount
2853
NextLifecycle = $Term.NextLifecycle
2954
Tenant = $_.Tenant
3055
}
@@ -35,5 +60,4 @@ function Get-CIPPAlertExpiringLicenses {
3560

3661
} catch {
3762
}
38-
}
39-
63+
}

0 commit comments

Comments
 (0)