@@ -55,15 +55,19 @@ function Invoke-CIPPStandardIntuneTemplate {
5555 Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Failed to get existing."
5656 }
5757 if ($ExistingPolicy ) {
58- Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Found existing policy."
59- $RawJSON = Get-CIPPTextReplacement - Text $RawJSON - TenantFilter $Tenant
60- Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Grabbing JSON existing."
61- $JSONExistingPolicy = $ExistingPolicy.cippconfiguration | ConvertFrom-Json - ErrorAction SilentlyContinue
62- Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Got existing JSON. Converting RawJSON to Template"
63- $JSONTemplate = $RawJSON | ConvertFrom-Json
64- Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Converted RawJSON to Template."
65- Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Comparing JSON."
66- $Compare = Compare-CIPPIntuneObject - ReferenceObject $JSONTemplate - DifferenceObject $JSONExistingPolicy - compareType $Request.body.Type - ErrorAction SilentlyContinue
58+ try {
59+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Found existing policy."
60+ $RawJSON = Get-CIPPTextReplacement - Text $RawJSON - TenantFilter $Tenant
61+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Grabbing JSON existing."
62+ $JSONExistingPolicy = $ExistingPolicy.cippconfiguration | ConvertFrom-Json
63+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Got existing JSON. Converting RawJSON to Template"
64+ $JSONTemplate = $RawJSON | ConvertFrom-Json
65+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Converted RawJSON to Template."
66+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Comparing JSON."
67+ $Compare = Compare-CIPPIntuneObject - ReferenceObject $JSONTemplate - DifferenceObject $JSONExistingPolicy - compareType $Request.body.Type - ErrorAction SilentlyContinue
68+ } catch {
69+ Write-Host " The compare failed. The error was: $ ( $_.Exception.Message ) "
70+ }
6771 Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Compared JSON: $ ( $Compare | ConvertTo-Json - Compress) "
6872 } else {
6973 Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - No existing policy found."
0 commit comments