Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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