Search-GPO.ps1
something exciting
Some information about the exciting thing
Table of contents generated with markdown-toc
Script
$String = "*something*"
$Domain = "COMPANY.LOCAL"
$NearestDC = (Get-ADDomainController -Discover -NextClosestSite).Name
#Get a list of GPOs from the domain
$GPOs = Get-GPO -All -Domain $Domain -Server $NearestDC | Sort-Object DisplayName
#Go through each Object and check its XML against $String
Foreach ($GPO in $GPOs) {
Write-Host "Working on $($GPO.DisplayName)"
#Get Current GPO Report (XML)
$CurrentGPOReport = Get-GPOReport -Guid $GPO.Id -ReportType Xml -Domain $Domain -Server $NearestDC
If ($CurrentGPOReport -match $String) {
Write-Host "A Group Policy matching ""$($String)"" has been found:" -Foregroundcolor Green
Write-Host "- GPO Name: $($GPO.DisplayName)" -Foregroundcolor Green
Write-Host "- GPO Id: $($GPO.Id)" -Foregroundcolor Green
Write-Host "- GPO Status: $($GPO.GpoStatus)" -Foregroundcolor Green
}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.