Skip to content

Instantly share code, notes, and snippets.

@SasStu
Last active October 18, 2020 23:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SasStu/103f5affd6bee2be72a1018f0f33da05 to your computer and use it in GitHub Desktop.
Save SasStu/103f5affd6bee2be72a1018f0f33da05 to your computer and use it in GitHub Desktop.
#Requires -Modules GPWMIFilter
#Source: https://gallery.technet.microsoft.com/scriptcenter/Group-Policy-WMI-filter-38a188f3
function Import-GPOBaselines {
param(
# Specifies a path to one or more locations.
[Parameter(Mandatory = $true,
Position = 0,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Path to the folder containing the exported GPO baseline folder.")]
[Alias("PSPath")]
[ValidateNotNullOrEmpty()]
[ValidateScript( {Test-path -Path $_ -PathType Container} )]
[string[]]
$Path
)
$reports = Get-ChildItem -Recurse -path $Path -Filter 'gpreport.xml'
foreach ($report in $reports) {
[XML]$XML = Get-Content -Path $report.fullname
$BuildVersion = $report.FullName.Split('\')[-4].split('-')[-1]
$GPName = $BuildVersion + ' - ' + $Xml.gpo.Name
$BackupID = $report.FullName.Split('\')[-2].replace('{', '').replace('}', '')
$BackupPath = Split-path -path (Split-Path -path $report.FullName -Parent) -Parent
$GPO = Import-GPO -BackupId $BackupID -Path $BackupPath -TargetName $GPName -CreateIfNeeded
$wmifilter = Get-GPWmiFilter -All | Where-Object {$_.name -match $BuildVersion}
$GPO.WmiFilter = $wmifilter
}
}
Import-GPOBaselines -Path 'ExportPath'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment