Created
February 14, 2023 09:51
-
-
Save FriedrichWeinmann/0780bf9092b089b26909453ae87a3ae6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-GpoBackupName { | |
[CmdletBinding()] | |
param ( | |
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
[Alias('FullName')] | |
[string] | |
$Path | |
) | |
process { | |
foreach ($folder in $Path) { | |
$datafile = Join-Path $Path 'Backup.xml' | |
[xml]$xml = Get-Content $datafile | |
$xml.GroupPolicyBackupScheme.GroupPolicyObject.GroupPolicyCoreSettings.DisplayName.'#cdata-section' | |
} | |
} | |
} | |
function Restore-GpoExtended { | |
[Cmdletbinding()] | |
Param ( | |
[string] | |
$Path = '.' | |
) | |
$resolvedPath = Resolve-Path $Path | |
$allGpos = Get-Gpo -All | |
$names = Get-ChildItem -Path $resolvedPath | Get-GpoBackupName | |
foreach ($name in $names) { | |
if ($allGpos.DisplayName -notcontains $name) { $Null = New-Gpo -Name $name } | |
Import-Gpo -Path $resolvedPath -BackupGpoName $name -TargetName $name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment