@@ -10,6 +10,7 @@ function Get-CIPPAlertExpiringLicenses {
1010 $InputValue ,
1111 $TenantFilter
1212 )
13+
1314 try {
1415 # Parse input parameters - default to 30 days if not specified
1516 # Support both old format (direct value) and new format (object with properties)
@@ -22,41 +23,53 @@ function Get-CIPPAlertExpiringLicenses {
2223 $UnassignedOnly = $false
2324 }
2425
25- $AlertData = Get-CIPPLicenseOverview - TenantFilter $TenantFilter | ForEach-Object {
26- $UnassignedCount = [ int ] $_ .CountAvailable
26+ $AlertData = @ (
27+ Get-CIPPLicenseOverview - TenantFilter $TenantFilter | ForEach-Object {
2728
28- # If unassigned only filter is enabled, skip licenses with no unassigned units
29- if ($UnassignedOnly -and $UnassignedCount -le 0 ) {
30- return
31- }
29+ $UnassignedCount = [int ]$_.CountAvailable
3230
33- foreach ( $Term in $TermData ) {
34- if ($Term .DaysUntilRenew -lt $DaysThreshold - and $Term .DaysUntilRenew -gt 0 ) {
35- $Message = if ( $UnassignedOnly ) {
36- " $ ( $_ .License ) has $UnassignedCount unassigned license(s) expiring in $ ( $Term .DaysUntilRenew ) days. The estimated term is $ ( $Term .Term ) "
37- } else {
38- " $ ( $_ .License ) will expire in $ ( $Term .DaysUntilRenew ) days. The estimated term is $ ( $Term .Term ) "
39- }
31+ # If unassigned only filter is enabled, skip licenses with no unassigned units
32+ if ($UnassignedOnly - and $UnassignedCount -le 0 ) {
33+ return
34+ }
35+
36+ # FIX: term rows are in TermInfo on the overview object
37+ $TermData = @ ( $_ .TermInfo )
4038
41- Write-Host $Message
42- [PSCustomObject ]@ {
43- Message = $Message
44- License = $_.License
45- SkuId = $_.skuId
46- DaysUntilRenew = $Term.DaysUntilRenew
47- Term = $Term.Term
48- Status = $Term.Status
49- TotalLicenses = $Term.TotalLicenses
50- CountUsed = $_.CountUsed
51- CountAvailable = $UnassignedCount
52- NextLifecycle = $Term.NextLifecycle
53- Tenant = $_.Tenant
39+ foreach ($Term in $TermData ) {
40+ $DaysUntilRenew = [int ]$Term.DaysUntilRenew
41+
42+ if ($DaysUntilRenew -lt $DaysThreshold -and $DaysUntilRenew -gt 0 ) {
43+
44+ $Message = if ($UnassignedOnly ) {
45+ " $ ( $_.License ) has $UnassignedCount unassigned license(s) expiring in $DaysUntilRenew days. The estimated term is $ ( $Term.Term ) "
46+ } else {
47+ " $ ( $_.License ) will expire in $DaysUntilRenew days. The estimated term is $ ( $Term.Term ) "
48+ }
49+
50+ [PSCustomObject ]@ {
51+ Message = $Message
52+ License = $_.License
53+ SkuId = $_.skuId
54+ DaysUntilRenew = $DaysUntilRenew
55+ Term = $Term.Term
56+ Status = $Term.Status
57+ TotalLicenses = $Term.TotalLicenses
58+ CountUsed = $_.CountUsed
59+ CountAvailable = $UnassignedCount
60+ NextLifecycle = $Term.NextLifecycle
61+ Tenant = $_.Tenant
62+ }
5463 }
5564 }
5665 }
57- }
66+ )
67+
5868 Write-AlertTrace - cmdletName $MyInvocation.MyCommand - tenantFilter $TenantFilter - data $AlertData
5969
6070 } catch {
71+ Write-AlertTrace - cmdletName $MyInvocation.MyCommand - tenantFilter $TenantFilter - error $_
72+ throw
6173 }
6274}
75+ ``
0 commit comments