Skip to content

Commit a7bd06e

Browse files
Merge pull request KelvinTegelaar#1427 from CHRIS-BRANNON/dev
Fix 90 Day Guest Filter
2 parents e0e15f3 + 31fb2be commit a7bd06e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ function Invoke-CIPPStandardDisableGuests {
3232
param($Tenant, $Settings)
3333
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableGuests'
3434

35-
$Lookup = (Get-Date).AddDays(-90).ToUniversalTime().ToString('o')
35+
$90Days = (Get-Date).AddDays(-90).ToUniversalTime()
36+
$Lookup = $90Days.ToString('o')
3637
$AuditLookup = (Get-Date).AddDays(-7).ToUniversalTime().ToString('o')
3738

38-
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$filter=(signInActivity/lastSuccessfulSignInDateTime le $Lookup)&`$select=id,UserPrincipalName,signInActivity,mail,userType,accountEnabled" -scope 'https://graph.microsoft.com/.default' -tenantid $Tenant |
39-
Where-Object { $_.userType -eq 'Guest' -and $_.AccountEnabled -eq $true }
39+
$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 |
40+
Where-Object { $_.signInActivity.lastSuccessfulSignInDateTime -le $90Days }
4041

4142
$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 |
4243
ForEach-Object { $_.targetResources[0].id } | Select-Object -Unique)

0 commit comments

Comments
 (0)