Skip to content

Commit 9385d28

Browse files
committed
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents f553905 + 642873a commit 9385d28

File tree

3 files changed

+119
-67
lines changed

3 files changed

+119
-67
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
4+
name: Build and deploy Powershell project to Azure Function App - cipp27qz5
5+
6+
on:
7+
push:
8+
branches:
9+
- dev
10+
workflow_dispatch:
11+
12+
env:
13+
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
14+
15+
jobs:
16+
deploy:
17+
runs-on: windows-latest
18+
19+
steps:
20+
- name: 'Checkout GitHub Action'
21+
uses: actions/checkout@v4
22+
23+
- name: 'Run Azure Functions Action'
24+
uses: Azure/functions-action@v1
25+
id: fa
26+
with:
27+
app-name: 'cipp27qz5'
28+
slot-name: 'Production'
29+
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
30+
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_821C9A2723884E2E85AC262B12EB26F7 }}

Modules/CIPPCore/Public/Compare-CIPPIntuneObject.ps1

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ function Compare-CIPPIntuneObject {
6969
[string]$PropertyName
7070
)
7171
return ($PropertyName -like '*@OData*' -or
72-
$PropertyName -like '#microsoft.graph*' -or
73-
$excludeProps -contains $PropertyName)
72+
$PropertyName -like '#microsoft.graph*' -or
73+
$excludeProps -contains $PropertyName)
7474
}
7575

7676
# Recursive function to compare objects deeply
@@ -83,7 +83,7 @@ function Compare-CIPPIntuneObject {
8383
$Object2,
8484

8585
[Parameter(Mandatory = $false)]
86-
[string]$PropertyPath = ""
86+
[string]$PropertyPath = ''
8787
)
8888

8989
# If both objects are null or empty, they're equal
@@ -94,20 +94,20 @@ function Compare-CIPPIntuneObject {
9494
# If one object is null but the other isn't, they're different
9595
if (($null -eq $Object1 -or $Object1 -eq '') -xor ($null -eq $Object2 -or $Object2 -eq '')) {
9696
$result.Add([PSCustomObject]@{
97-
Property = $PropertyPath
98-
ExpectedValue = if ($null -eq $Object1) { '' } else { $Object1 }
99-
ReceivedValue = if ($null -eq $Object2) { '' } else { $Object2 }
100-
})
97+
Property = $PropertyPath
98+
ExpectedValue = if ($null -eq $Object1) { '' } else { $Object1 }
99+
ReceivedValue = if ($null -eq $Object2) { '' } else { $Object2 }
100+
})
101101
return
102102
}
103103

104104
# If objects are of different types, they're different
105105
if ($Object1.GetType() -ne $Object2.GetType()) {
106106
$result.Add([PSCustomObject]@{
107-
Property = $PropertyPath
108-
ExpectedValue = $Object1
109-
ReceivedValue = $Object2
110-
})
107+
Property = $PropertyPath
108+
ExpectedValue = $Object1
109+
ReceivedValue = $Object2
110+
})
111111
return
112112
}
113113

@@ -122,25 +122,25 @@ function Compare-CIPPIntuneObject {
122122
$newPath = if ($PropertyPath) { "$PropertyPath.$key" } else { $key }
123123

124124
if ($Object1.ContainsKey($key) -and $Object2.ContainsKey($key)) {
125-
Compare-ObjectsRecursively -Object1 $Object1[$key] -Object2 $Object2[$key] -PropertyPath $newPath
126-
}
127-
elseif ($Object1.ContainsKey($key)) {
125+
#only run if both props are not null
126+
if ($Object1[$key] -and $Object2[$key]) {
127+
Compare-ObjectsRecursively -Object1 $Object1[$key] -Object2 $Object2[$key] -PropertyPath $newPath
128+
}
129+
} elseif ($Object1.ContainsKey($key)) {
128130
$result.Add([PSCustomObject]@{
129-
Property = $newPath
130-
ExpectedValue = $Object1[$key]
131-
ReceivedValue = ''
132-
})
133-
}
134-
else {
131+
Property = $newPath
132+
ExpectedValue = $Object1[$key]
133+
ReceivedValue = ''
134+
})
135+
} else {
135136
$result.Add([PSCustomObject]@{
136-
Property = $newPath
137-
ExpectedValue = ''
138-
ReceivedValue = $Object2[$key]
139-
})
137+
Property = $newPath
138+
ExpectedValue = ''
139+
ReceivedValue = $Object2[$key]
140+
})
140141
}
141142
}
142-
}
143-
elseif ($Object1 -is [Array] -or $Object1 -is [System.Collections.IList]) {
143+
} elseif ($Object1 -is [Array] -or $Object1 -is [System.Collections.IList]) {
144144
# Compare arrays
145145
$maxLength = [Math]::Max($Object1.Count, $Object2.Count)
146146

@@ -149,24 +149,21 @@ function Compare-CIPPIntuneObject {
149149

150150
if ($i -lt $Object1.Count -and $i -lt $Object2.Count) {
151151
Compare-ObjectsRecursively -Object1 $Object1[$i] -Object2 $Object2[$i] -PropertyPath $newPath
152-
}
153-
elseif ($i -lt $Object1.Count) {
152+
} elseif ($i -lt $Object1.Count) {
154153
$result.Add([PSCustomObject]@{
155-
Property = $newPath
156-
ExpectedValue = $Object1[$i]
157-
ReceivedValue = ''
158-
})
159-
}
160-
else {
154+
Property = $newPath
155+
ExpectedValue = $Object1[$i]
156+
ReceivedValue = ''
157+
})
158+
} else {
161159
$result.Add([PSCustomObject]@{
162-
Property = $newPath
163-
ExpectedValue = ''
164-
ReceivedValue = $Object2[$i]
165-
})
160+
Property = $newPath
161+
ExpectedValue = ''
162+
ReceivedValue = $Object2[$i]
163+
})
166164
}
167165
}
168-
}
169-
elseif ($Object1 -is [PSCustomObject] -or $Object1.PSObject.Properties.Count -gt 0) {
166+
} elseif ($Object1 -is [PSCustomObject] -or $Object1.PSObject.Properties.Count -gt 0) {
170167
# Compare PSCustomObjects or objects with properties
171168
$allPropertyNames = @(
172169
$Object1.PSObject.Properties | Select-Object -ExpandProperty Name
@@ -181,35 +178,35 @@ function Compare-CIPPIntuneObject {
181178
$prop2Exists = $Object2.PSObject.Properties.Name -contains $propName
182179

183180
if ($prop1Exists -and $prop2Exists) {
184-
Compare-ObjectsRecursively -Object1 $Object1.$propName -Object2 $Object2.$propName -PropertyPath $newPath
185-
}
186-
elseif ($prop1Exists) {
181+
#only run if both props are not null
182+
if ($Object1.$propName -and $Object2.$propName) {
183+
Compare-ObjectsRecursively -Object1 $Object1.$propName -Object2 $Object2.$propName -PropertyPath $newPath
184+
}
185+
} elseif ($prop1Exists) {
187186
$result.Add([PSCustomObject]@{
188-
Property = $newPath
189-
ExpectedValue = $Object1.$propName
190-
ReceivedValue = ''
191-
})
192-
}
193-
else {
187+
Property = $newPath
188+
ExpectedValue = $Object1.$propName
189+
ReceivedValue = ''
190+
})
191+
} else {
194192
$result.Add([PSCustomObject]@{
195-
Property = $newPath
196-
ExpectedValue = ''
197-
ReceivedValue = $Object2.$propName
198-
})
193+
Property = $newPath
194+
ExpectedValue = ''
195+
ReceivedValue = $Object2.$propName
196+
})
199197
}
200198
}
201-
}
202-
else {
199+
} else {
203200
# Compare primitive values
204201
$val1 = $Object1.ToString()
205202
$val2 = $Object2.ToString()
206203

207204
if ($val1 -ne $val2) {
208205
$result.Add([PSCustomObject]@{
209-
Property = $PropertyPath
210-
ExpectedValue = $val1
211-
ReceivedValue = $val2
212-
})
206+
Property = $PropertyPath
207+
ExpectedValue = $val1
208+
ReceivedValue = $val2
209+
})
213210
}
214211
}
215212
}
@@ -228,7 +225,10 @@ function Compare-CIPPIntuneObject {
228225
}
229226

230227
# Start the recursive comparison
231-
Compare-ObjectsRecursively -Object1 $obj1 -Object2 $obj2
228+
#only do the compare if the objects are not null
229+
if ($obj1 -and $obj2) {
230+
Compare-ObjectsRecursively -Object1 $obj1 -Object2 $obj2
231+
}
232232

233233
# If no differences found, return null
234234
if ($result.Count -eq 0) {

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,45 @@ 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) {
50-
$RawJSON = Get-CIPPTextReplacement -Text $RawJSON -TenantFilter $Tenant
51-
$JSONExistingPolicy = $ExistingPolicy.cippconfiguration | ConvertFrom-Json
52-
$JSONTemplate = $RawJSON | ConvertFrom-Json
53-
$Compare = Compare-CIPPIntuneObject -ReferenceObject $JSONTemplate -DifferenceObject $JSONExistingPolicy -compareType $Request.body.Type
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+
}
71+
Write-Host "IntuneTemplate: $($Template.TemplateList.value) - Compared JSON: $($Compare | ConvertTo-Json -Compress)"
72+
} else {
73+
Write-Host "IntuneTemplate: $($Template.TemplateList.value) - No existing policy found."
5474
}
5575
if ($Compare) {
76+
Write-Host "IntuneTemplate: $($Template.TemplateList.value) - Compare found differences."
5677
[PSCustomObject]@{
5778
MatchFailed = $true
5879
displayname = $displayname
@@ -67,6 +88,7 @@ function Invoke-CIPPStandardIntuneTemplate {
6788
templateId = $Template.TemplateList.value
6889
}
6990
} else {
91+
Write-Host "IntuneTemplate: $($Template.TemplateList.value) - No differences found."
7092
[PSCustomObject]@{
7193
MatchFailed = $false
7294
displayname = $displayname
@@ -86,7 +108,7 @@ function Invoke-CIPPStandardIntuneTemplate {
86108
If ($true -in $Settings.remediate) {
87109
Write-Host 'starting template deploy'
88110
foreach ($TemplateFile in $CompareList | Where-Object -Property remediate -EQ $true) {
89-
Write-Host "working on template deploy: $($Template.displayname)"
111+
Write-Host "working on template deploy: $($TemplateFile.displayname)"
90112
try {
91113
$TemplateFile.customGroup ? ($TemplateFile.AssignTo = $TemplateFile.customGroup) : $null
92114
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

Comments
 (0)