Skip to content

Commit 583240e

Browse files
committed
Logging backwards compatibility
1 parent 440f5f2 commit 583240e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardDisableGuests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ function Invoke-CIPPStandardDisableGuests {
3434

3535
param($Tenant, $Settings)
3636
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableGuests'
37-
$checkDays = if ($Settings.days) { $Settings.days } else { 90 }
37+
$checkDays = if ($Settings.days) { $Settings.days } else { 90 } # Default to 90 days if not set. Pre v8.5.0 compatibility
3838
$Days = (Get-Date).AddDays(-$checkDays).ToUniversalTime()
3939
$Lookup = $Days.ToString('o')
4040
$AuditLookup = (Get-Date).AddDays(-7).ToUniversalTime().ToString('o')
4141

4242
try {
4343
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$filter=createdDateTime le $Lookup and userType eq 'Guest' and accountEnabled eq true &`$select=id,UserPrincipalName,signInActivity,mail,userType,accountEnabled,createdDateTime,externalUserState" -scope 'https://graph.microsoft.com/.default' -tenantid $Tenant |
44-
Where-Object { $_.signInActivity.lastSuccessfulSignInDateTime -le $Days }
44+
Where-Object { $_.signInActivity.lastSuccessfulSignInDateTime -le $Days }
4545
} catch {
4646
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
4747
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the DisableGuests state for $Tenant. Error: $ErrorMessage" -Sev Error
4848
return
4949
}
5050

5151
$RecentlyReactivatedUsers = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/auditLogs/directoryAudits?`$filter=activityDisplayName eq 'Enable account' and activityDateTime ge $AuditLookup" -scope 'https://graph.microsoft.com/.default' -tenantid $Tenant |
52-
ForEach-Object { $_.targetResources[0].id } | Select-Object -Unique)
52+
ForEach-Object { $_.targetResources[0].id } | Select-Object -Unique)
5353

5454
$GraphRequest = $GraphRequest | Where-Object { -not ($RecentlyReactivatedUsers -contains $_.id) }
5555

@@ -65,7 +65,7 @@ function Invoke-CIPPStandardDisableGuests {
6565
}
6666
}
6767
} else {
68-
Write-LogMessage -API 'Standards' -tenant $tenant -message "No guests accounts with a login longer than $($Settings.days) days ago." -sev Info
68+
Write-LogMessage -API 'Standards' -tenant $tenant -message "No guests accounts with a login longer than $checkDays days ago." -sev Info
6969
}
7070

7171
}
@@ -74,9 +74,9 @@ function Invoke-CIPPStandardDisableGuests {
7474
if ($GraphRequest.Count -gt 0) {
7575
$Filtered = $GraphRequest | Select-Object -Property UserPrincipalName, id, signInActivity, mail, userType, accountEnabled, externalUserState
7676
Write-StandardsAlert -message "Guests accounts with a login longer than 90 days ago: $($GraphRequest.count)" -object $Filtered -tenant $tenant -standardName 'DisableGuests' -standardId $Settings.standardId
77-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Guests accounts with a login longer than $($Settings.days) days ago: $($GraphRequest.count)" -sev Info
77+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Guests accounts with a login longer than $checkDays days ago: $($GraphRequest.count)" -sev Info
7878
} else {
79-
Write-LogMessage -API 'Standards' -tenant $tenant -message "No guests accounts with a login longer than $($Settings.days) days ago." -sev Info
79+
Write-LogMessage -API 'Standards' -tenant $tenant -message "No guests accounts with a login longer than $checkDays days ago." -sev Info
8080
}
8181
}
8282
if ($Settings.report -eq $true) {

0 commit comments

Comments
 (0)