From 6703625c00d57cb0581f5544e8892015e1031f62 Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Tue, 14 Apr 2026 19:02:06 +0200 Subject: [PATCH] fix(rename): guard Add prefix against double-prefixing Skip objects whose displayName or description already starts with the requested prefix. This makes Add prefix idempotent. --- Scripts/Bulk-RenamePolicies.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/Bulk-RenamePolicies.ps1 b/Scripts/Bulk-RenamePolicies.ps1 index e4e94df..0721e6f 100644 --- a/Scripts/Bulk-RenamePolicies.ps1 +++ b/Scripts/Bulk-RenamePolicies.ps1 @@ -332,7 +332,7 @@ foreach($obj in $selectedObjects) switch($mode) { "Search and replace" { if($oldName -match $searchPattern) { $newName = $oldName -replace $searchPattern, $replacePattern } } - "Add prefix" { $newName = "$prefix$oldName" } + "Add prefix" { if(-not $oldName.StartsWith($prefix)) { $newName = "$prefix$oldName" } } "Strip prefix" { if($oldName.StartsWith($prefix)) { $newName = $oldName.Substring($prefix.Length) } } } } @@ -341,7 +341,7 @@ foreach($obj in $selectedObjects) switch($mode) { "Search and replace" { if($oldDesc -match $searchPattern) { $newDesc = $oldDesc -replace $searchPattern, $replacePattern } } - "Add prefix" { $newDesc = "$prefix$oldDesc" } + "Add prefix" { if(-not $oldDesc.StartsWith($prefix)) { $newDesc = "$prefix$oldDesc" } } "Strip prefix" { if($oldDesc.StartsWith($prefix)) { $newDesc = $oldDesc.Substring($prefix.Length) } } } }