Skip to content

Commit 4b5dfc6

Browse files
authored
Merge pull request #599 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 0b6b5f1 + 7f3d7e0 commit 4b5dfc6

File tree

7 files changed

+57
-42
lines changed

7 files changed

+57
-42
lines changed

.github/workflows/master_cippkdsva.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

Modules/CIPPCore/Public/GraphHelper/New-GraphGetRequest.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ function New-GraphGetRequest {
4747
$headers[$key] = $extraHeaders[$key]
4848
}
4949
}
50+
51+
if (!$headers['User-Agent']) {
52+
$headers['User-Agent'] = "CIPP/$($global:CippVersion ?? '1.0')"
53+
}
54+
5055
# Track consecutive Graph API failures
5156
$TenantsTable = Get-CippTable -tablename Tenants
5257
$Filter = "PartitionKey eq 'Tenants' and (defaultDomainName eq '{0}' or customerId eq '{0}')" -f $tenantid

Modules/CIPPCore/Public/GraphHelper/New-GraphPOSTRequest.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ function New-GraphPOSTRequest {
2828
}
2929
}
3030

31+
if (!$headers['User-Agent']) {
32+
$headers['User-Agent'] = "CIPP/$($global:CippVersion ?? '1.0')"
33+
}
34+
3135
if (!$contentType) {
3236
$contentType = 'application/json; charset=utf-8'
3337
}

Modules/CIPPCore/Public/New-CIPPTemplateRun.ps1

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,23 @@ function New-CIPPTemplateRun {
8888
Write-Information 'Creating templates for found Conditional Access Policies'
8989
foreach ($policy in $policies) {
9090
try {
91+
$Hash = Get-StringHash -String ($policy | ConvertTo-Json -Depth 100 -Compress)
92+
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $policy.displayName } | Select-Object -First 1
93+
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
94+
"Policy $($policy.displayName) found, SHA matches, skipping template creation"
95+
continue
96+
}
9197
$Template = New-CIPPCATemplate -TenantFilter $TenantFilter -JSON $policy
9298
#check existing templates, if the displayName is the same, overwrite it.
93-
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $policy.displayName } | Select-Object -First 1
99+
94100
if ($ExistingPolicy -and $ExistingPolicy.PartitionKey -eq 'CATemplate') {
95101
"Policy $($policy.displayName) found, updating template"
96102
Add-CIPPAzDataTableEntity @Table -Entity @{
97103
JSON = "$Template"
98104
RowKey = $ExistingPolicy.GUID
99105
PartitionKey = 'CATemplate'
100106
GUID = $ExistingPolicy.GUID
107+
SHA = $Hash
101108
} -Force
102109
} else {
103110
"Policy $($policy.displayName) not found in existing templates, creating new template"
@@ -107,6 +114,7 @@ function New-CIPPTemplateRun {
107114
RowKey = "$GUID"
108115
PartitionKey = 'CATemplate'
109116
GUID = "$GUID"
117+
SHA = $Hash
110118
}
111119
}
112120

@@ -133,8 +141,15 @@ function New-CIPPTemplateRun {
133141
$URLName = (($url).split('?') | Select-Object -First 1) -replace 'https://graph.microsoft.com/beta/deviceManagement/', ''
134142
foreach ($Policy in $Policies) {
135143
try {
136-
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName $URLName -ID $Policy.ID
144+
$Hash = Get-StringHash -String ($Policy | ConvertTo-Json -Depth 100 -Compress)
137145
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $Template.DisplayName } | Select-Object -First 1
146+
147+
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
148+
"Policy $($Policy.displayName) found, SHA matches, skipping template creation"
149+
continue
150+
}
151+
152+
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName $URLName -ID $Policy.ID
138153
if ($ExistingPolicy -and $ExistingPolicy.PartitionKey -eq 'IntuneTemplate') {
139154
"Policy $($Template.DisplayName) found, updating template"
140155
$object = [PSCustomObject]@{
@@ -149,6 +164,8 @@ function New-CIPPTemplateRun {
149164
JSON = "$object"
150165
RowKey = $ExistingPolicy.GUID
151166
PartitionKey = 'IntuneTemplate'
167+
Package = $ExistingPolicy.Package
168+
SHA = $Hash
152169
} -Force
153170
} else {
154171
"Policy $($Template.DisplayName) not found in existing templates, creating new template"
@@ -165,6 +182,7 @@ function New-CIPPTemplateRun {
165182
JSON = "$object"
166183
RowKey = "$GUID"
167184
PartitionKey = 'IntuneTemplate'
185+
SHA = $Hash
168186
} -Force
169187
}
170188
} catch {
@@ -180,8 +198,14 @@ function New-CIPPTemplateRun {
180198
'intunecompliance' {
181199
Write-Information "Backup Intune Compliance Policies for $TenantFilter"
182200
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/deviceCompliancePolicies?$top=999' -tenantid $TenantFilter | ForEach-Object {
201+
$Hash = Get-StringHash -String (ConvertTo-Json -Depth 100 -Compress -InputObject $_)
202+
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $_.DisplayName } | Select-Object -First 1
203+
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
204+
"Policy $($_.DisplayName) found, SHA matches, skipping template creation"
205+
continue
206+
}
207+
183208
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName 'deviceCompliancePolicies' -ID $_.ID
184-
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $Template.DisplayName } | Select-Object -First 1
185209
if ($ExistingPolicy -and $ExistingPolicy.PartitionKey -eq 'IntuneTemplate') {
186210
"Policy $($Template.DisplayName) found, updating template"
187211
$object = [PSCustomObject]@{
@@ -196,6 +220,8 @@ function New-CIPPTemplateRun {
196220
JSON = "$object"
197221
RowKey = $ExistingPolicy.GUID
198222
PartitionKey = 'IntuneTemplate'
223+
Package = $ExistingPolicy.Package
224+
SHA = $Hash
199225
} -Force
200226
} else {
201227
"Policy $($Template.DisplayName) not found in existing templates, creating new template"
@@ -212,17 +238,23 @@ function New-CIPPTemplateRun {
212238
JSON = "$object"
213239
RowKey = "$GUID"
214240
PartitionKey = 'IntuneTemplate'
241+
SHA = $Hash
215242
} -Force
216243
}
217-
218244
}
219245
}
220246

221247
'intuneprotection' {
222248
Write-Information "Backup Intune Protection Policies for $TenantFilter"
223249
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceAppManagement/managedAppPolicies?$top=999' -tenantid $TenantFilter | ForEach-Object {
250+
$Hash = Get-StringHash -String (ConvertTo-Json -Depth 100 -Compress -InputObject $_)
251+
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $_.DisplayName } | Select-Object -First 1
252+
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
253+
"Policy $($_.DisplayName) found, SHA matches, skipping template creation"
254+
continue
255+
}
256+
224257
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName 'managedAppPolicies' -ID $_.ID
225-
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $Template.DisplayName } | Select-Object -First 1
226258
if ($ExistingPolicy -and $ExistingPolicy.PartitionKey -eq 'IntuneTemplate') {
227259
"Policy $($Template.DisplayName) found, updating template"
228260
$object = [PSCustomObject]@{
@@ -237,6 +269,8 @@ function New-CIPPTemplateRun {
237269
JSON = "$object"
238270
RowKey = $ExistingPolicy.GUID
239271
PartitionKey = 'IntuneTemplate'
272+
Package = $ExistingPolicy.Package
273+
SHA = $Hash
240274
} -Force
241275
} else {
242276
"Policy $($Template.DisplayName) not found in existing templates, creating new template"
@@ -253,6 +287,7 @@ function New-CIPPTemplateRun {
253287
JSON = "$object"
254288
RowKey = "$GUID"
255289
PartitionKey = 'IntuneTemplate'
290+
SHA = $Hash
256291
} -Force
257292
}
258293
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Invoke-CIPPStandardAddDMARCToMOERA {
5151

5252
$CurrentInfo = $Domains | ForEach-Object {
5353
# Get current DNS records that matches _dmarc hostname and TXT type
54-
$RecordsResponse = New-GraphGetRequest -scope 'https://admin.microsoft.com/.default' -TenantID $Tenant -Uri "https://admin.microsoft.com/admin/api/Domains/Records?domainName=$($_.Name)" -extraHeaders @{'User-Agent' = 'CIPP/1.0' }
54+
$RecordsResponse = New-GraphGetRequest -scope 'https://admin.microsoft.com/.default' -TenantID $Tenant -Uri "https://admin.microsoft.com/admin/api/Domains/Records?domainName=$($_.Name)"
5555
$AllRecords = $RecordsResponse | Select-Object -ExpandProperty DnsRecords
5656
$CurrentRecords = $AllRecords | Where-Object { $_.HostName -eq '_dmarc' -and $_.Type -eq 'TXT' }
5757
Write-Information "Found $($CurrentRecords.count) DMARC records for domain $($_.Name)"

Modules/CIPPCore/Public/Tools/Import-CommunityTemplate.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ function Import-CommunityTemplate {
4242
$excludedTenants = $ExistingJSON.excludedTenants
4343
$NewJSON.tenantFilter = $tenantFilter
4444
$NewJSON.excludedTenants = $excludedTenants
45-
46-
# Extract package tag from existing template
47-
$PackageTag = $Existing.Package
48-
if ($PackageTag) {
49-
$Template | Add-Member -MemberType NoteProperty -Name Package -Value $PackageTag -Force
50-
}
5145
}
5246
}
5347

@@ -169,6 +163,11 @@ function Import-CommunityTemplate {
169163
GUID = $ID
170164
RowKey = $ID
171165
}
166+
167+
if ($Existing -and $Existing.Package) {
168+
$entity.Package = $Existing.Package
169+
}
170+
172171
Add-CIPPAzDataTableEntity @Table -Entity $entity -Force
173172

174173
}

profile.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Set-Location -Path $PSScriptRoot
7777
$CurrentVersion = (Get-Content .\version_latest.txt).trim()
7878
$Table = Get-CippTable -tablename 'Version'
7979
Write-Information "Function App: $($env:WEBSITE_SITE_NAME) | API Version: $CurrentVersion | PS Version: $($PSVersionTable.PSVersion)"
80+
$global:CippVersion = $CurrentVersion
81+
8082
$LastStartup = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'Version' and RowKey eq '$($env:WEBSITE_SITE_NAME)'"
8183
if (!$LastStartup -or $CurrentVersion -ne $LastStartup.Version) {
8284
Write-Information "Version has changed from $($LastStartup.Version ?? 'None') to $CurrentVersion"

0 commit comments

Comments
 (0)