Skip to content

Commit 62388d5

Browse files
fix compare for policies
1 parent 2f8da33 commit 62388d5

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

Modules/CIPPCore/Public/Set-CIPPIntunePolicy.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Set-CIPPIntunePolicy {
1212
$tenantFilter
1313
)
1414
$APINAME = 'Set-CIPPIntunePolicy'
15-
15+
1616
$RawJSON = Get-CIPPTextReplacement -TenantFilter $tenantFilter -Text $RawJSON
1717

1818
try {
@@ -65,8 +65,8 @@ function Set-CIPPIntunePolicy {
6565
$ExistingID = $CheckExististing | Where-Object -Property displayName -EQ $displayname
6666
$ExistingData = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($ExistingID.id)')/definitionValues" -tenantid $tenantFilter
6767
$DeleteJson = $RawJSON | ConvertFrom-Json -Depth 10
68-
$DeleteJson.deletedIds = @($ExistingData.id)
69-
$DeleteJson.added = @()
68+
$DeleteJson | Add-Member -MemberType NoteProperty -Name 'deletedIds' -Value @($ExistingData.id) -Force
69+
$DeleteJson | Add-Member -MemberType NoteProperty -Name 'added' -Value @() -Force
7070
$DeleteJson = ConvertTo-Json -Depth 10 -InputObject $DeleteJson
7171
$DeleteRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($ExistingID.id)')/updateDefinitionValues" -tenantid $tenantFilter -type POST -body $DeleteJson
7272
$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL('$($ExistingID.id)')/updateDefinitionValues" -tenantid $tenantFilter -type POST -body $RawJSON

Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ function Set-CIPPStandardsCompareField {
44
$FieldValue,
55
$TenantFilter
66
)
7-
Write-Host "Shoehorn: Set-CIPPStandardsCompareField - $FieldName - $FieldValue - $TenantFilter"
87
$Table = Get-CippTable -tablename 'CippStandardsReports'
98
$TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Tenant
109
#if the fieldname does not contain standards. prepend it.

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardIntuneTemplate.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function Invoke-CIPPStandardIntuneTemplate {
3737
$Request = @{body = $null }
3838

3939
$CompareList = foreach ($Template in $Settings) {
40-
Write-Host "working on template: $($Template | ConvertTo-Json)"
4140
$Request.body = (Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object -Property RowKey -Like "$($Template.TemplateList.value)*").JSON | ConvertFrom-Json -ErrorAction SilentlyContinue
4241
if ($Request.body -eq $null) {
4342
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to find template $($Template.TemplateList.value). Has this Intune Template been deleted?" -sev 'Error'
@@ -84,13 +83,13 @@ function Invoke-CIPPStandardIntuneTemplate {
8483
}
8584
}
8685

87-
If ($Settings.remediate -eq $true) {
86+
If ($true -in $Settings.remediate) {
8887
Write-Host 'starting template deploy'
89-
foreach ($Template in $CompareList | Where-Object -Property remediate -EQ $true) {
90-
Write-Host "working on template deploy: $($Template | ConvertTo-Json)"
88+
foreach ($TemplateFile in $CompareList | Where-Object -Property remediate -EQ $true) {
89+
Write-Host "working on template deploy: $($Template.displayname)"
9190
try {
92-
$Template.customGroup ? ($Template.AssignTo = $Template.customGroup) : $null
93-
Set-CIPPIntunePolicy -TemplateType $Template.body.Type -Description $description -DisplayName $displayname -RawJSON $RawJSON -AssignTo $Template.AssignTo -ExcludeGroup $Template.excludeGroup -tenantFilter $Tenant
91+
$TemplateFile.customGroup ? ($TemplateFile.AssignTo = $TemplateFile.customGroup) : $null
92+
Set-CIPPIntunePolicy -TemplateType $TemplateFile.body.Type -Description $TemplateFile.description -DisplayName $TemplateFile.displayname -RawJSON $templateFile.rawJSON -AssignTo $TemplateFile.AssignTo -ExcludeGroup $TemplateFile.excludeGroup -tenantFilter $Tenant
9493
} catch {
9594
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
9695
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to create or update Intune Template $PolicyName, Error: $ErrorMessage" -sev 'Error'

0 commit comments

Comments
 (0)