Skip to content

Commit

Permalink
Add error handling to Get-MyDefenderHealthIssues.ps1
Browse files Browse the repository at this point in the history
- Implement try-catch block for error handling during health issue retrieval
- Log warning message if health issues cannot be retrieved
  • Loading branch information
PrzemyslawKlys committed Feb 26, 2025
1 parent 0cb117b commit 8f8afce
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Public/Get-MyDefenderHealthIssues.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@
}
}
Write-Verbose -Message "Get-MyDefenderHealthIssues - Querying Microsoft Defender Health Issues with filter: '$($QueryParameters.Filter)'"
$Data = Get-MgBetaSecurityIdentityHealthIssue @QueryParameters
try {
$Data = Get-MgBetaSecurityIdentityHealthIssue @QueryParameters -ErrorAction Stop
} catch {
Write-Warning -Message "Get-MyDefenderHealthIssues - Unable to retrieve health issues. Error: $($_.Exception.Message)"
return $false
}
$Data | ForEach-Object {
[PSCustomObject] @{
DisplayName = $_.displayName # : Sensor service failed to start
Expand Down

0 comments on commit 8f8afce

Please sign in to comment.