@@ -7,6 +7,7 @@ function Import-CommunityTemplate {
77 [Parameter (Mandatory = $true )]
88 $Template ,
99 $SHA ,
10+ $MigrationTable ,
1011 [switch ]$Force
1112 )
1213
@@ -15,12 +16,14 @@ function Import-CommunityTemplate {
1516
1617 if ($Template.RowKey ) {
1718 Write-Host " This is going to be a direct write to table, it's a CIPP template. We're writing $ ( $Template.RowKey ) "
19+ $Template = $Template | Select-Object * - ExcludeProperty timestamp
1820 Add-CIPPAzDataTableEntity @Table - Entity $Template - Force
1921 } else {
20- if ($Template.groupTypes ) { $Type = ' Group' }
22+ if ($Template.mailNickname ) { $Type = ' Group' }
2123 if ($Template .' @odata.type' -like ' *conditionalAccessPolicy*' ) { $Type = ' ConditionalAccessPolicy' }
22-
24+ Write-Host " The type is $Type "
2325 switch - Wildcard ($Type ) {
26+
2427 ' *Group*' {
2528 $RawJsonObj = [PSCustomObject ]@ {
2629 Displayname = $Template.displayName
@@ -29,7 +32,7 @@ function Import-CommunityTemplate {
2932 username = $Template.mailNickname
3033 GUID = $Template.id
3134 groupType = ' generic'
32- } | ConvertTo-Json - Depth 100 - Compress
35+ } | ConvertTo-Json - Depth 100
3336 $entity = @ {
3437 JSON = " $RawJsonObj "
3538 PartitionKey = ' GroupTemplate'
@@ -38,8 +41,10 @@ function Import-CommunityTemplate {
3841 RowKey = $Template.id
3942 }
4043 Add-CIPPAzDataTableEntity @Table - Entity $entity - Force
44+ break
4145 }
4246 ' *conditionalAccessPolicy*' {
47+ Write-Host $MigrationTable
4348 $Template = ([pscustomobject ]$Template ) | ForEach-Object {
4449 $NonEmptyProperties = $_.psobject.Properties | Where-Object { $null -ne $_.Value } | Select-Object - ExpandProperty Name
4550 $_ | Select-Object - Property $NonEmptyProperties
@@ -48,6 +53,12 @@ function Import-CommunityTemplate {
4853 $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'
4954 Remove-ODataProperties - Object $Template
5055 $RawJson = ConvertTo-Json - InputObject $Template - Depth 100 - Compress
56+ # Replace the ids with the displayname by using the migration table, this is a simple find and replace each instance in the JSON.
57+ $MigrationTable.objects | ForEach-Object {
58+ if ($RawJson -match $_.ID ) {
59+ $RawJson = $RawJson.Replace ($_.ID , $ ($_.DisplayName ))
60+ }
61+ }
5162 $entity = @ {
5263 JSON = " $RawJson "
5364 PartitionKey = ' CATemplate'
@@ -56,6 +67,7 @@ function Import-CommunityTemplate {
5667 RowKey = $ID
5768 }
5869 Add-CIPPAzDataTableEntity @Table - Entity $entity - Force
70+ break
5971 }
6072 default {
6173 $URLName = switch - Wildcard ($Template .' @odata.id' ) {
0 commit comments