Public/Search-GPOForString.ps1

function Search-GPOForString
{
    <#
        .SYNOPSIS
        Search all GPOs for the specified string value
     
        .DESCRIPTION
        Search all GPOs for the specified string value
 
        .NOTES
        Version : 1.0
        Author : Tony Murray
        Date : 13/07/2016
             
        Requires ActiveDirectory module (run from computer with RSAT installed)
     
        .EXAMPLE
        Find-ActiveRDPSessions
    #>
    
    param (
        [Parameter(Mandatory=$TRUE)][String]$SearchFor
    )
    Import-Module grouppolicy
    
    # Set the domain to search for GPOs
    $DomainName = $env:USERDNSDOMAIN
    
    # Find all GPOs in the current domain
    write-host "Finding all the GPOs in $DomainName"
    $allGposInDomain = Get-GPO -All -Domain $DomainName
    
    # Look through each GPO's XML for the string
    Write-Host "Starting search...."
    foreach ($gpo in $allGposInDomain)
    {
        $report = Get-GPOReport -Guid $gpo.Id -ReportType Xml
        if ($report -match $SearchFor)
        {
            write-host "********** Match found in: $($gpo.DisplayName) **********"
        } # end if
        else
        {
            Write-Host "No match in: $($gpo.DisplayName)"
        } # end else
    } # end foreach
} #END function