@@ -6,19 +6,69 @@ function Import-CommunityTemplate {
66 param (
77 [Parameter (Mandatory = $true )]
88 $Template ,
9+ $SHA ,
910 [switch ]$Force
1011 )
1112
1213 $Table = Get-CippTable - TableName ' templates'
13- $Filter = " PartitionKey eq '$Type '"
1414
15- $CippTemplates = (Get-CIPPAzDataTableEntity @Table - Filter $Filter ) | ForEach-Object {
16- $GUID = $_.RowKey
17- $data = $_.JSON | ConvertFrom-Json
18- $data | Add-Member - NotePropertyName ' GUID' - NotePropertyValue $GUID - Force
19- $data
15+
16+ if ($Template.RowKey ) {
17+ Write-Host " This is going to be a direct write to table, it's a CIPP template. We're writing $ ( $Template.RowKey ) "
18+ Add-CIPPAzDataTableEntity @Table - Entity $Template - Force
19+ } else {
20+ switch - Wildcard ($Template .' @odata.type' ) {
21+ ' *conditionalAccessPolicy*' {
22+ $Template = ([pscustomobject ]$Template ) | ForEach-Object {
23+ $NonEmptyProperties = $_.psobject.Properties | Where-Object { $null -ne $_.Value } | Select-Object - ExpandProperty Name
24+ $_ | Select-Object - Property $NonEmptyProperties
25+ }
26+ $id = $Template.id
27+ $Template = $Template | Select-Object * - ExcludeProperty lastModifiedDateTime, ' assignments' , ' #microsoft*' , ' *@odata.navigationLink' , ' *@odata.associationLink' , ' *@odata.context' , ' ScopeTagIds' , ' supportsScopeTags' , ' createdDateTime' , ' @odata.id' , ' @odata.editLink' , ' *odata.type' , ' roleScopeTagIds@odata.type' , createdDateTime, ' createdDateTime@odata.type'
28+ Remove-ODataProperties - Object $Template
29+ $RawJson = ConvertTo-Json - InputObject $Template - Depth 100 - Compress
30+ $entity = @ {
31+ JSON = " $RawJson "
32+ PartitionKey = ' CATemplate'
33+ SHA = $SHA
34+ GUID = $ID
35+ RowKey = $ID
36+ }
37+ Add-CIPPAzDataTableEntity @Table - Entity $entity - Force
38+ }
39+ default {
40+ $URLName = switch - Wildcard ($Template .' @odata.id' ) {
41+ ' *CompliancePolicies*' { ' DeviceCompliancePolicies' }
42+ ' *deviceConfigurations*' { ' Device' }
43+ ' *DriverUpdateProfiles*' { ' windowsDriverUpdateProfiles' }
44+ ' *SettingsCatalog*' { ' Catalog' }
45+ ' *configurationPolicies*' { ' Catalog' }
46+ }
47+ $id = $Template.id
48+ $RawJson = $Template | Select-Object * - ExcludeProperty id, lastModifiedDateTime, ' assignments' , ' #microsoft*' , ' *@odata.navigationLink' , ' *@odata.associationLink' , ' *@odata.context' , ' ScopeTagIds' , ' supportsScopeTags' , ' createdDateTime' , ' @odata.id' , ' @odata.editLink' , ' lastModifiedDateTime@odata.type' , ' roleScopeTagIds@odata.type' , createdDateTime, ' createdDateTime@odata.type'
49+ Remove-ODataProperties - Object $RawJson
50+ $RawJson = $RawJson | ConvertTo-Json - Depth 100 - Compress
51+
52+ # create a new template
53+ $RawJsonObj = [PSCustomObject ]@ {
54+ Displayname = $Template.displayName ?? $template.Name
55+ Description = $Template.Description
56+ RAWJson = $RawJson
57+ Type = $URLName
58+ GUID = $ID
59+ } | ConvertTo-Json - Depth 100 - Compress
60+
61+ $entity = @ {
62+ JSON = " $RawJsonObj "
63+ PartitionKey = ' IntuneTemplate'
64+ SHA = $SHA
65+ GUID = $ID
66+ RowKey = $ID
67+ }
68+ Add-CIPPAzDataTableEntity @Table - Entity $entity - Force
69+
70+ }
71+ }
2072 }
2173
22- $Contents = $Template.content
23- Write-Host ($Contents )
2474}
0 commit comments