If you need to find a GPO that has a particular setting or text, then this is the script for you. It was written by BritV8, but I wanted to host it on my own site to ensure it’s always available.
This PowerShell script takes an input / parameter of a bit of text, then downloads all your group policies as XML files, then searches through them all to find which policies contain the text.
To use it, simply run up PowerShell as administrator, then run the script. It will prompt you for some text that you want to search you group policies for. Enter the search text and hit enter.
❗ Note: If you want to search for anything with a backslash (“\”) character, you must double up each backslash, because \ is an escape character in PowerShell. For example, to search for \\myServer\Share, you need to enter this search string: \\\\myServer\\Share.
Here’s the script:
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[String]
$StringToFind
)
Begin
{
$GPOsToCheck = get-gpo -all |Sort-Object -property displayname
Write-Host ” Checking through” $GPOsToCheck.count “GPO’s”
}
Process
{
$ListOFAffectedGPOs = @()
$count = 1
$GPOsToCheckCount = $GPOsToCheck.count
foreach ($item in $GPOsToCheck)
{
$Result = Get-GPOReport -name $item.DisplayName -ReportType XML
if ($Result -match $StringToFind)
{
$ListOFAffectedGPOs += $item.DisplayName
}
else
{
}
Write-Host “$count of $GPOsToCheckCount”
$count++
}
Write-Host “List of GPO’s that contain $StringToFind” -ForegroundColor Green
$ListOFAffectedGPOs
$ListOFAffectedGPOs.count
}
End
{
}