From ff539f9ec172328cdd47b9cd8324ae676a763cef Mon Sep 17 00:00:00 2001 From: Mykhailo-Roit <88772563+Mykhailo-Roit@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:45:48 +0200 Subject: [PATCH 1/3] feat: replace_with_assignments import type --- Extensions/MSGraph.psm1 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Extensions/MSGraph.psm1 b/Extensions/MSGraph.psm1 index 26fe015..8862005 100644 --- a/Extensions/MSGraph.psm1 +++ b/Extensions/MSGraph.psm1 @@ -43,6 +43,10 @@ function Invoke-InitializeModule Name = "Replace (Preview)" Value = "replace" }, + [PSCustomObject]@{ + Name = "Replace with assignments (Preview)" + Value = "replace_with_assignments" + }, [PSCustomObject]@{ Name = "Update (Preview)" Value = "update" @@ -2353,7 +2357,10 @@ function Reset-GraphObject # Clone the object before removing properties $obj = $fileObj.Object | ConvertTo-Json -Depth 50 | ConvertFrom-Json Start-GraphPreImport $obj $objectType - Remove-Property $obj "Assignments" + if ($global:cbImportType.SelectedValue -eq "replace"){ + # will use the assignments from the file for "replace_with_assignments" type + Remove-Property $obj "Assignments" + } Remove-Property $obj "isAssigned" if($global:cbImportType.SelectedValue -eq "update") @@ -2417,7 +2424,7 @@ function Reset-GraphObject } return $true } - elseif($global:cbImportType.SelectedValue -eq "replace") + elseif($global:cbImportType.SelectedValue -in @("replace","replace_with_assignments")) { $replace = $true $import = $true @@ -2466,8 +2473,13 @@ function Reset-GraphObject } } } - - Import-GraphObjectAssignment $newObj $objectType $curObject.Object.Assignments $fileObj.FileInfo.FullName -CopyAssignments | Out-Null + if ($global:cbImportType.SelectedValue -eq "replace") + { + Import-GraphObjectAssignment $newObj $objectType $curObject.Object.Assignments $fileObj.FileInfo.FullName -CopyAssignments | Out-Null + } + else { + Import-GraphObjectAssignment $newObj $objectType $obj.Assignments $file.FileInfo.FullName | Out-Null + } if($delete) { From 28022615a1de633014e74c66d645441b9cac913e Mon Sep 17 00:00:00 2001 From: Mykhailo-Roit <88772563+Mykhailo-Roit@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:58:36 +0200 Subject: [PATCH 2/3] feat: add tooltip description for 'Replace with assignments' option in import forms --- Xaml/BulkImportForm.xaml | 1 + Xaml/ImportForm.xaml | 1 + 2 files changed, 2 insertions(+) diff --git a/Xaml/BulkImportForm.xaml b/Xaml/BulkImportForm.xaml index 307fe08..daab27f 100644 --- a/Xaml/BulkImportForm.xaml +++ b/Xaml/BulkImportForm.xaml @@ -85,6 +85,7 @@ Always import: Always try to import the object. No detction of existing object (Default) Skip if object exists: Skip import if there is an existing object with the same name and type Replace: If an object is detected, it will be deleted. The assignments will be copied to the new imported object + Replace with assignments: If an object is detected, it will be deleted. The assignments will be copied from the imported object Update: If an object is detected, settings will be replaced from the import file diff --git a/Xaml/ImportForm.xaml b/Xaml/ImportForm.xaml index 9ac70d7..ab2a279 100644 --- a/Xaml/ImportForm.xaml +++ b/Xaml/ImportForm.xaml @@ -76,6 +76,7 @@ Always import: Always try to import the object. No detction of existing object (Default) Skip if object exists: Skip import if there is an existing object with the same name and type Replace: If an object is detected, it will be deleted. The assignments will be copied to the new imported object + Replace with assignments: If an object is detected, it will be deleted. The assignments will be copied from the imported object Update: If an object is detected, settings will be replaced from the import file From 381967c8cfeeeaa9f87027aeb236f88bdf87c494 Mon Sep 17 00:00:00 2001 From: Mykhailo-Roit <88772563+Mykhailo-Roit@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:40:21 +0200 Subject: [PATCH 3/3] fix conditions --- Extensions/MSGraph.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extensions/MSGraph.psm1 b/Extensions/MSGraph.psm1 index 8862005..0b07e62 100644 --- a/Extensions/MSGraph.psm1 +++ b/Extensions/MSGraph.psm1 @@ -2357,7 +2357,7 @@ function Reset-GraphObject # Clone the object before removing properties $obj = $fileObj.Object | ConvertTo-Json -Depth 50 | ConvertFrom-Json Start-GraphPreImport $obj $objectType - if ($global:cbImportType.SelectedValue -eq "replace"){ + if ($global:cbImportType.SelectedValue -ne "replace_with_assignments"){ # will use the assignments from the file for "replace_with_assignments" type Remove-Property $obj "Assignments" }