Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#Requires -Modules GPWMIFilter
function Import-GPOBaselines {
# 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.")]
[ValidateScript( {Test-path -Path $_ -PathType Container} )]
$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 {$ -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