Skip to content

Instantly share code, notes, and snippets.

@FriedrichWeinmann
Created February 14, 2023 09:51
Show Gist options
  • Save FriedrichWeinmann/0780bf9092b089b26909453ae87a3ae6 to your computer and use it in GitHub Desktop.
Save FriedrichWeinmann/0780bf9092b089b26909453ae87a3ae6 to your computer and use it in GitHub Desktop.
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