Skip to content

Commit f13462d

Browse files
committed
add json error handling for invalid reports
1 parent 381c406 commit f13462d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Modules/CIPPCore/Public/Functions/Get-CIPPTenantAlignment.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ function Get-CIPPTenantAlignment {
7272
if ($FieldValue -is [System.Boolean]) {
7373
$FieldValue = [bool]$FieldValue
7474
} elseif ($FieldValue -like '*{*') {
75-
$FieldValue = ConvertFrom-Json -Depth 100 -InputObject $FieldValue -ErrorAction SilentlyContinue
75+
try {
76+
$FieldValue = ConvertFrom-Json -Depth 100 -InputObject $FieldValue -ErrorAction SilentlyContinue
77+
} catch {
78+
Write-Warning "$($FieldName) standard report could not be loaded: $($_.Exception.Message)"
79+
$FieldValue = [PSCustomObject]@{
80+
Error = "Invalid JSON format: $($_.Exception.Message)"
81+
OriginalValue = $FieldValue
82+
}
83+
}
7684
} else {
7785
$FieldValue = [string]$FieldValue
7886
}

0 commit comments

Comments
 (0)