Repair migratetable replace string

This commit is contained in:
2024-02-16 09:26:19 +00:00
parent 1e6222cf9e
commit 67591cfd95

View File

@@ -227,51 +227,47 @@ Process
#Prepare GPO #Prepare GPO
#Reference https://gallery.technet.microsoft.com/Migrate-Group-Policy-2b5067d8#content #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. #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" 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 $content = Get-Content $MigrationTable
foreach($object in $ADGroupMapping){ foreach($object in $ADGroupMapping.GetEnumerator()){
$content.Replace("[[$($object.Name)]]", $object.Value) $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" 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 $content = Get-Content $MigrationTable
foreach($object in $ADGroupMapping){ foreach($object in $ADGroupMapping.GetEnumerator()){
$content.Replace("[[$($object.Name)]]", $object.Value) $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" 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 $content = Get-Content $MigrationTable
foreach($object in $ADGroupMapping){ foreach($object in $ADGroupMapping.GetEnumerator()){
$content.Replace("[[$($object.Name)]]", $object.Value) $content = $content.Replace("[[$($object.Name)]]", $object.Value)
} }
Set-Content $MigrationTable $content | Set-Content $MigrationTable
#Import GPO #Import GPO
Write-Message -Message "Importing GPO policy SEC-ADMIN-DOMAIN" 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) $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"} 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" 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) $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"} 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" 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) $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"} 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 End