@@ -35,22 +35,30 @@ function Invoke-CIPPStandardIntuneTemplate {
3535 $Table = Get-CippTable - tablename ' templates'
3636 $Filter = " PartitionKey eq 'IntuneTemplate'"
3737 $Request = @ {body = $null }
38-
38+ Write-Host " IntuneTemplate: Starting process. Settings are: $ ( $Settings | ConvertTo-Json - Compress ) "
3939 $CompareList = foreach ($Template in $Settings ) {
40+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Trying to find template"
4041 $Request.body = (Get-CIPPAzDataTableEntity @Table - Filter $Filter | Where-Object - Property RowKey -Like " $ ( $Template.TemplateList.value ) *" ).JSON | ConvertFrom-Json - ErrorAction SilentlyContinue
4142 if ($Request.body -eq $null ) {
4243 Write-LogMessage - API ' Standards' - tenant $tenant - message " Failed to find template $ ( $Template.TemplateList.value ) . Has this Intune Template been deleted?" - sev ' Error'
4344 continue
4445 }
46+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Got template."
47+
4548 $displayname = $request.body.Displayname
4649 $description = $request.body.Description
4750 $RawJSON = $Request.body.RawJSON
48- $ExistingPolicy = Get-CIPPIntunePolicy - tenantFilter $Tenant - DisplayName $displayname - TemplateType $Request.body.Type
51+ try {
52+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Grabbing existing Policy"
53+ $ExistingPolicy = Get-CIPPIntunePolicy - tenantFilter $Tenant - DisplayName $displayname - TemplateType $Request.body.Type
54+ } catch {
55+ Write-Host " IntuneTemplate: $ ( $Template.TemplateList.value ) - Failed to get existing."
56+ }
4957 if ($ExistingPolicy ) {
5058 $RawJSON = Get-CIPPTextReplacement - Text $RawJSON - TenantFilter $Tenant
51- $JSONExistingPolicy = $ExistingPolicy.cippconfiguration | ConvertFrom-Json
59+ $JSONExistingPolicy = $ExistingPolicy.cippconfiguration | ConvertFrom-Json - ErrorAction SilentlyContinue
5260 $JSONTemplate = $RawJSON | ConvertFrom-Json
53- $Compare = Compare-CIPPIntuneObject - ReferenceObject $JSONTemplate - DifferenceObject $JSONExistingPolicy - compareType $Request.body.Type
61+ $Compare = Compare-CIPPIntuneObject - ReferenceObject $JSONTemplate - DifferenceObject $JSONExistingPolicy - compareType $Request.body.Type - ErrorAction SilentlyContinue
5462 }
5563 if ($Compare ) {
5664 [PSCustomObject ]@ {
@@ -86,7 +94,7 @@ function Invoke-CIPPStandardIntuneTemplate {
8694 If ($true -in $Settings.remediate ) {
8795 Write-Host ' starting template deploy'
8896 foreach ($TemplateFile in $CompareList | Where-Object - Property remediate -EQ $true ) {
89- Write-Host " working on template deploy: $ ( $Template .displayname ) "
97+ Write-Host " working on template deploy: $ ( $TemplateFile .displayname ) "
9098 try {
9199 $TemplateFile.customGroup ? ($TemplateFile.AssignTo = $TemplateFile.customGroup ) : $null
92100 Set-CIPPIntunePolicy - TemplateType $TemplateFile.body.Type - Description $TemplateFile.description - DisplayName $TemplateFile.displayname - RawJSON $templateFile.rawJSON - AssignTo $TemplateFile.AssignTo - ExcludeGroup $TemplateFile.excludeGroup - tenantFilter $Tenant
0 commit comments