From 67591cfd95de55591fb3ae079613d9806b396c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0t=C4=9Bp=C3=A1n?= Date: Fri, 16 Feb 2024 09:26:19 +0000 Subject: [PATCH] Repair migratetable replace string --- Import-TIER-GPO.ps1 | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/Import-TIER-GPO.ps1 b/Import-TIER-GPO.ps1 index f47c948..efa50d9 100644 --- a/Import-TIER-GPO.ps1 +++ b/Import-TIER-GPO.ps1 @@ -227,51 +227,47 @@ Process #Prepare GPO #Reference https://gallery.technet.microsoft.com/Migrate-Group-Policy-2b5067d8#content #Change variables in the GPO migration table to suit environment by recursing through the migration table and then changing the values to suit the current environment. - Write-Message -Message "Modifying GPO migration table" - $MigrationTable = "$WorkFolderPath\Migration.migtable" - (Get-Content $MigrationTable).replace("\\SHAREFOLDER", "$ShareFolder") | Set-Content $MigrationTable - Write-Message -Message "Modifying GPO migration table for SEC-ADMIN-DOMAIN" - $MigrationTable = "$WorkFolderPath\SEC-Admin-Domain.migtable" + $MigrationTable = "$WorkFolderPath\GPO_tier\SEC-Admin-Domain.migtable" $content = Get-Content $MigrationTable - foreach($object in $ADGroupMapping){ - $content.Replace("[[$($object.Name)]]", $object.Value) + foreach($object in $ADGroupMapping.GetEnumerator()){ + $content = $content.Replace("[[$($object.Name)]]", $object.Value) } - Set-Content $MigrationTable + $content | Set-Content $MigrationTable Write-Message -Message "Modifying GPO migration table for SEC-ADMIN-SERVERS" - $MigrationTable = "$WorkFolderPath\SEC-Admin-Servers.migtable" + $MigrationTable = "$WorkFolderPath\GPO_tier\SEC-Admin-Servers.migtable" $content = Get-Content $MigrationTable - foreach($object in $ADGroupMapping){ - $content.Replace("[[$($object.Name)]]", $object.Value) + foreach($object in $ADGroupMapping.GetEnumerator()){ + $content = $content.Replace("[[$($object.Name)]]", $object.Value) } - Set-Content $MigrationTable + $content | Set-Content $MigrationTable Write-Message -Message "Modifying GPO migration table for SEC-ADMIN-WORKSTATIONS" - $MigrationTable = "$WorkFolderPath\SEC-Admin-Workstations.migtable" + $MigrationTable = "$WorkFolderPath\GPO_tier\SEC-Admin-Workstations.migtable" $content = Get-Content $MigrationTable - foreach($object in $ADGroupMapping){ - $content.Replace("[[$($object.Name)]]", $object.Value) + foreach($object in $ADGroupMapping.GetEnumerator()){ + $content = $content.Replace("[[$($object.Name)]]", $object.Value) } - Set-Content $MigrationTable + $content | Set-Content $MigrationTable #Import GPO Write-Message -Message "Importing GPO policy SEC-ADMIN-DOMAIN" $GPOName = $(Write-Host "Enter name for GPO policy DOMAIN TIER (T0) [SEC-Admin-Domain] " -ForegroundColor Yellow -NoNewline; Read-Host) if ($GPOName -eq '') {$GPOName = "SEC-Admin-Domain"} - Import-GPO -CreateIfNeeded -path "$WorkFolderPath" -BackupGpoName 'SEC-Admin-Domain' -TargetName $GPOName -MigrationTable "$WorkFolderPath\SEC-Admin-Domain.migtable" + Import-GPO -CreateIfNeeded -path "$WorkFolderPath\GPO_tier" -BackupGpoName 'SEC-Admin-Domain' -TargetName $GPOName -MigrationTable "$WorkFolderPath\GPO_tier\SEC-Admin-Domain.migtable" Write-Message -Message "Importing GPO policy SEC-ADMIN-SERVERS" $GPOName = $(Write-Host "Enter name for GPO policy SERVERS TIER (T1) [SEC-Admin-Servers] " -ForegroundColor Yellow -NoNewline; Read-Host) if ($GPOName -eq '') {$GPOName = "SEC-Admin-Servers"} - Import-GPO -CreateIfNeeded -path "$WorkFolderPath" -BackupGpoName 'SEC-Admin-Servers' -TargetName $GPOName -MigrationTable "$WorkFolderPath\SEC-Admin-Servers.migtable" + Import-GPO -CreateIfNeeded -path "$WorkFolderPath\GPO_tier" -BackupGpoName 'SEC-Admin-Servers' -TargetName $GPOName -MigrationTable "$WorkFolderPath\GPO_tier\SEC-Admin-Servers.migtable" Write-Message -Message "Importing GPO policy SEC-ADMIN-WORKSTATIONS" $GPOName = $(Write-Host "Enter name for GPO policy SERVERS TIER (T1) [SEC-Admin-Workstations] " -ForegroundColor Yellow -NoNewline; Read-Host) if ($GPOName -eq '') {$GPOName = "SEC-Admin-Workstations"} - Import-GPO -CreateIfNeeded -path "$WorkFolderPath" -BackupGpoName 'SEC-Admin-Workstations' -TargetName $GPOName -MigrationTable "$WorkFolderPath\SEC-Admin-Workstations.migtable" + Import-GPO -CreateIfNeeded -path "$WorkFolderPath\GPO_tier" -BackupGpoName 'SEC-Admin-Workstations' -TargetName $GPOName -MigrationTable "$WorkFolderPath\GPO_tier\SEC-Admin-Workstations.migtable" } End