Skip to content

Commit 5c9c312

Browse files
committed
Added Copilot suggestion so Test-IsInGroup consistently returns a boolean. Error paths no longer return $null, which previously caused silent false negatives on transient Graph errors and bypassed caching. Instead, errors are surfaced explicitly and a boolean result is returned in all code paths.
1 parent 045d6d8 commit 5c9c312

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

M365/MDO/MDOThreatPolicyChecker.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ begin {
194194
$groupMembers = Get-MgGroupMember -GroupId $GroupObjectId -All -ErrorAction Stop
195195
} catch {
196196
Write-Host "Error getting group members for $GroupObjectId`:`n$_" -ForegroundColor Red
197-
return $null
197+
$memberCache[$cacheKey] = $false
198+
return $false
198199
}
199200

200201
# Check if the email address is in the group
@@ -209,7 +210,8 @@ begin {
209210
$user = Get-MgUser -UserId $member.Id -ErrorAction Stop
210211
} catch {
211212
Write-Host "Error getting user with Id $($member.Id):`n$_" -ForegroundColor Red
212-
return $null
213+
$memberCache[$cacheKey] = $false
214+
return $false
213215
}
214216
# Compare the user's email address with the $email parameter
215217
if ($user.Mail -eq $Email.ToString()) {

0 commit comments

Comments
 (0)