Skip to content

Commit e37b4ed

Browse files
authored
Merge pull request #635 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents f0f9466 + 5f55eaf commit e37b4ed

File tree

13 files changed

+66
-25
lines changed

13 files changed

+66
-25
lines changed

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertQuarantineReleaseRequests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
MessageId = $Message.MessageId
3939
Subject = $Message.Subject
4040
SenderAddress = $Message.SenderAddress
41-
RecipientAddress = $Message.RecipientAddress
41+
RecipientAddress = $Message.RecipientAddress -join '; '
4242
Type = $Message.Type
4343
PolicyName = $Message.PolicyName
4444
ReleaseStatus = $Message.ReleaseStatus

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecListBackup.ps1

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@ function Invoke-ExecListBackup {
2121

2222
if ($NameOnly) {
2323
$Processed = foreach ($item in $Result) {
24-
$properties = $item.PSObject.Properties | Where-Object { $_.Name -notin @('TenantFilter', 'ETag', 'PartitionKey', 'RowKey', 'Timestamp') -and $_.Value }
25-
[PSCustomObject]@{
26-
BackupName = $item.RowKey
27-
Timestamp = $item.Timestamp
28-
Items = $properties.Name
24+
$properties = $item.PSObject.Properties | Where-Object { $_.Name -notin @('TenantFilter', 'ETag', 'PartitionKey', 'RowKey', 'Timestamp', 'OriginalEntityId', 'SplitOverProps', 'PartIndex') -and $_.Value }
25+
26+
if ($Type -eq 'Scheduled') {
27+
[PSCustomObject]@{
28+
TenantFilter = $item.RowKey -match '^(.*?)_' | ForEach-Object { $matches[1] }
29+
BackupName = $item.RowKey
30+
Timestamp = $item.Timestamp
31+
Items = $properties.Name
32+
}
33+
} else {
34+
[PSCustomObject]@{
35+
BackupName = $item.RowKey
36+
Timestamp = $item.Timestamp
37+
}
38+
2939
}
3040
}
3141
$Result = $Processed | Sort-Object Timestamp -Descending

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/MEM/Invoke-ListIntuneTemplates.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ function Invoke-ListIntuneTemplates {
3939
$data | Add-Member -NotePropertyName 'Type' -NotePropertyValue $JSONData.Type -Force
4040
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.RowKey -Force
4141
$data | Add-Member -NotePropertyName 'package' -NotePropertyValue $_.Package -Force
42-
$data | Add-Member -NotePropertyName 'isSynced' -NotePropertyValue (![string]::IsNullOrEmpty($_.SHA))
42+
$data | Add-Member -NotePropertyName 'isSynced' -NotePropertyValue (![string]::IsNullOrEmpty($_.SHA)) -Force
43+
$data | Add-Member -NotePropertyName 'source' -NotePropertyValue $_.Source -Force
4344
$data
4445
} catch {
4546

@@ -65,6 +66,8 @@ function Invoke-ListIntuneTemplates {
6566
$data | Add-Member -NotePropertyName 'Type' -NotePropertyValue $JSONData.Type -Force
6667
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.RowKey -Force
6768
$data | Add-Member -NotePropertyName 'package' -NotePropertyValue $_.Package -Force
69+
$data | Add-Member -NotePropertyName 'source' -NotePropertyValue $_.Source -Force
70+
$data | Add-Member -NotePropertyName 'isSynced' -NotePropertyValue (![string]::IsNullOrEmpty($_.SHA)) -Force
6871
$data
6972
} catch {
7073

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-ListGroupTemplates.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function Invoke-ListGroupTemplates {
4848
allowExternal = $data.allowExternal
4949
username = $data.username
5050
GUID = $_.RowKey
51+
source = $_.Source
52+
isSynced = (![string]::IsNullOrEmpty($_.SHA))
5153
}
5254
} catch {
5355
Write-Information "Could not parse group template $($_.RowKey): $($_.Exception.Message)"

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Conditional/Invoke-ListCAtemplates.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function Invoke-ListCAtemplates {
3535
$row = $_
3636
$data = $row.JSON | ConvertFrom-Json -Depth 100 -ErrorAction Stop
3737
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $row.GUID -Force
38+
$data | Add-Member -NotePropertyName 'source' -NotePropertyValue $row.Source -Force
39+
$data | Add-Member -NotePropertyName 'isSynced' -NotePropertyValue (![string]::IsNullOrEmpty($row.SHA)) -Force
3840
$data
3941
} catch {
4042
Write-Warning "Failed to process CA template: $($row.RowKey) - $($_.Exception.Message)"

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function Invoke-listStandardTemplates {
2323
}
2424
if ($Data) {
2525
$Data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.GUID -Force
26+
$Data | Add-Member -NotePropertyName 'source' -NotePropertyValue $_.Source -Force
27+
$Data | Add-Member -NotePropertyName 'isSynced' -NotePropertyValue (![string]::IsNullOrEmpty($_.SHA)) -Force
2628

2729
if (!$Data.excludedTenants) {
2830
$Data | Add-Member -NotePropertyName 'excludedTenants' -NotePropertyValue @() -Force

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-UpdateTokensTimer.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function Start-UpdateTokensTimer {
6868
Write-Information "Found $($ExpiredSecrets.Count) expired application secrets for $AppId. Removing them."
6969
foreach ($Secret in $ExpiredSecrets) {
7070
try {
71-
New-GraphPostRequest -type DELETE -uri "https://graph.microsoft.com/v1.0/applications/$($PasswordCredentials.id)/removePassword" -Body "{`"keyId`":`"$($Secret.keyId)`"}" -NoAuthCheck $true -AsApp $true -ErrorAction Stop
71+
New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/applications/$($PasswordCredentials.id)/removePassword" -Body "{`"keyId`":`"$($Secret.keyId)`"}" -NoAuthCheck $true -AsApp $true -ErrorAction Stop
7272
Write-Information "Removed expired application secret with keyId $($Secret.keyId)."
7373
} catch {
7474
Write-LogMessage -API 'Update Tokens' -message "Error removing expired application secret with keyId $($Secret.keyId), see Log Data for details." -sev 'CRITICAL' -LogData (Get-CippException -Exception $_)

Modules/CIPPCore/Public/Get-CIPPBackup.ps1

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@ function Get-CIPPBackup {
1818
}
1919

2020
if ($NameOnly.IsPresent) {
21-
$Table.Property = @('PartitionKey', 'RowKey', 'Timestamp', 'OriginalEntityId')
21+
$Table.Property = @('RowKey')
2222
}
2323

2424
$Filter = $Conditions -join ' and '
2525
$Table.Filter = $Filter
26-
$Info = Get-CIPPAzDataTableEntity @Table -Debug
27-
if ($TenantFilter) {
28-
$Info = $Info | Where-Object { $_.TenantFilter -eq $TenantFilter }
26+
$Info = Get-CIPPAzDataTableEntity @Table
27+
28+
if ($NameOnly.IsPresent) {
29+
$Info = $Info | Where-Object { $_.RowKey -notmatch '-part[0-9]+$' }
30+
if ($TenantFilter) {
31+
$Info = $Info | Where-Object { $_.RowKey -match "^$($TenantFilter)_" }
32+
}
33+
} else {
34+
if ($TenantFilter -and $TenantFilter -ne 'AllTenants') {
35+
$Info = $Info | Where-Object { $_.TenantFilter -eq $TenantFilter }
36+
}
2937
}
3038
return $Info
3139
}

Modules/CIPPCore/Public/Get-CIPPDrift.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,17 @@ function Get-CIPPDrift {
280280
} else {
281281
'New'
282282
}
283+
$reason = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].Reason }
284+
$User = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].User }
283285
$PolicyDeviation = [PSCustomObject]@{
284286
standardName = $PolicyKey
285287
standardDisplayName = "Intune - $TenantPolicyName"
286288
expectedValue = 'This policy only exists in the tenant, not in the template.'
287289
receivedValue = $TenantPolicy.Policy
288290
state = 'current'
289291
Status = $Status
292+
Reason = $reason
293+
lastChangedByUser = $User
290294
}
291295
$PolicyDeviations.Add($PolicyDeviation)
292296
}
@@ -310,13 +314,17 @@ function Get-CIPPDrift {
310314
} else {
311315
'New'
312316
}
317+
$reason = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].Reason }
318+
$User = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].User }
313319
$PolicyDeviation = [PSCustomObject]@{
314320
standardName = $PolicyKey
315321
standardDisplayName = "Conditional Access - $($TenantCAPolicy.displayName)"
316322
expectedValue = 'This policy only exists in the tenant, not in the template.'
317323
receivedValue = $TenantCAPolicy | Out-String
318324
state = 'current'
319325
Status = $Status
326+
Reason = $reason
327+
lastChangedByUser = $User
320328
}
321329
$PolicyDeviations.Add($PolicyDeviation)
322330
}

Modules/CIPPCore/Public/New-CIPPTemplateRun.ps1

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function New-CIPPTemplateRun {
6464

6565
if (!$ExistingTemplate -or $UpdateNeeded) {
6666
$Template = (Get-GitHubFileContents -FullName $TemplateSettings.templateRepo.value -Branch $TemplateSettings.templateRepoBranch.value -Path $File.path).content | ConvertFrom-Json
67-
Import-CommunityTemplate -Template $Template -SHA $File.sha -MigrationTable $MigrationTable -LocationData $LocationData
67+
Import-CommunityTemplate -Template $Template -SHA $File.sha -MigrationTable $MigrationTable -LocationData $LocationData -Source $TemplateSettings.templateRepo.value
6868
if ($UpdateNeeded) {
6969
Write-Information "Template $($File.name) needs to be updated as the SHA is different"
7070
"Template $($File.name) updated"
@@ -114,7 +114,7 @@ function New-CIPPTemplateRun {
114114
foreach ($policy in $policies) {
115115
try {
116116
$Hash = Get-StringHash -String ($policy | ConvertTo-Json -Depth 100 -Compress)
117-
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.PartitionKey -eq 'CATemplate' -and $_.displayName -eq $policy.displayName } | Select-Object -First 1
117+
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.PartitionKey -eq 'CATemplate' -and $_.displayName -eq $policy.displayName -and $_.Source -eq $TenantFilter } | Select-Object -First 1
118118
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
119119
"CA Policy $($policy.displayName) found, SHA matches, skipping template creation"
120120
continue
@@ -184,16 +184,16 @@ function New-CIPPTemplateRun {
184184
$Hash = Get-StringHash -String ($Policy | ConvertTo-Json -Depth 100 -Compress)
185185
$DisplayName = $Policy.displayName ?? $Policy.name
186186

187-
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.PartitionKey -eq 'IntuneTemplate' -and $_.displayName -eq $DisplayName } | Select-Object -First 1
187+
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.PartitionKey -eq 'IntuneTemplate' -and $_.displayName -eq $DisplayName -and $_.Source -eq $TenantFilter } | Select-Object -First 1
188188

189189
Write-Information "Processing Intune Configuration Policy $($DisplayName) - $($ExistingPolicy ? 'Existing template found' : 'No existing template found')"
190190

191191
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
192-
"Intune Configuration Policy $($Policy.displayName) found, SHA matches, skipping template creation"
192+
"Intune Configuration Policy $($DisplayName) found, SHA matches, skipping template creation"
193193
continue
194194
}
195195

196-
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName $URLName -ID $Policy.ID
196+
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName $URLName -ID $Policy.id
197197
if ($ExistingPolicy -and $ExistingPolicy.PartitionKey -eq 'IntuneTemplate') {
198198
"Policy $($Template.DisplayName) found, updating template"
199199
$object = [PSCustomObject]@{
@@ -246,14 +246,15 @@ function New-CIPPTemplateRun {
246246
'intunecompliance' {
247247
Write-Information "Create Intune Compliance Policy Templates for $TenantFilter"
248248
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/deviceCompliancePolicies?$top=999' -tenantid $TenantFilter | ForEach-Object {
249+
$Policy = $_
249250
$Hash = Get-StringHash -String (ConvertTo-Json -Depth 100 -Compress -InputObject $_)
250-
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $_.DisplayName } | Select-Object -First 1
251+
$ExistingPolicy = $ExistingTemplates | Where-Object { $Policy.displayName -eq $_.DisplayName -and $_.Source -eq $TenantFilter } | Select-Object -First 1
251252
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
252253
"Intune Compliance Policy $($_.DisplayName) found, SHA matches, skipping template creation"
253254
continue
254255
}
255256

256-
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName 'deviceCompliancePolicies' -ID $_.ID
257+
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName 'deviceCompliancePolicies' -ID $Policy.id
257258
if ($ExistingPolicy -and $ExistingPolicy.PartitionKey -eq 'IntuneTemplate') {
258259
"Intune Compliance Policy $($Template.DisplayName) found, updating template"
259260
$object = [PSCustomObject]@{
@@ -299,14 +300,15 @@ function New-CIPPTemplateRun {
299300
'intuneprotection' {
300301
Write-Information "Create Intune Protection Policy Templates for $TenantFilter"
301302
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceAppManagement/managedAppPolicies?$top=999' -tenantid $TenantFilter | ForEach-Object {
303+
$Policy = $_
302304
$Hash = Get-StringHash -String (ConvertTo-Json -Depth 100 -Compress -InputObject $_)
303-
$ExistingPolicy = $ExistingTemplates | Where-Object { $_.displayName -eq $_.DisplayName } | Select-Object -First 1
305+
$ExistingPolicy = $ExistingTemplates | Where-Object { $Policy.displayName -eq $_.DisplayName -and $_.Source -eq $TenantFilter } | Select-Object -First 1
304306
if ($ExistingPolicy -and $ExistingPolicy.SHA -eq $Hash) {
305307
"Intune Protection Policy $($_.DisplayName) found, SHA matches, skipping template creation"
306308
continue
307309
}
308310

309-
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName 'managedAppPolicies' -ID $_.ID
311+
$Template = New-CIPPIntuneTemplate -TenantFilter $TenantFilter -URLName 'managedAppPolicies' -ID $Policy.id
310312
if ($ExistingPolicy -and $ExistingPolicy.PartitionKey -eq 'IntuneTemplate') {
311313
"Intune Protection Policy $($Template.DisplayName) found, updating template"
312314
$object = [PSCustomObject]@{

0 commit comments

Comments
 (0)