Scripts/Search-GPO.ps1
function Search-GPO { [CmdletBinding()] param ( [parameter(Mandatory, ValueFromPipeline=$true, ParameterSetName="String", HelpMessage="What string do you want to search for?")] $String ) begin { # 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" Import-Module grouppolicy $allGposInDomain = Get-GPO -All -Domain $DomainName $FoundGPOs = New-Object -TypeName System.Collections.ArrayList $ProgressCount=1 Write-Host "Starting search...." } process { foreach ($gpo in $allGposInDomain) { $report = Get-GPOReport -Guid $gpo.Id -ReportType Xml [int]$progress=$(($ProgressCount/$allGposInDomain.count)*100.) Write-Progress -Activity "Searching GPOs for the string: $($String)" -Status "$($progress)% Complete" -PercentComplete (($ProgressCount/$allGposInDomain.count)*100) $ProgressCount++ if ($report -match $String) { write-host "********** Match found in: $($gpo.DisplayName) **********" $FoundGPOs+=$gpo } } } end { Write-Progress -Activity "Searching GPOs for the string: $($String)" -Status "$($progress)% Complete" -PercentComplete 100 if ($FoundGPOs){ Write-Host "Search completed with $($FoundGPOs.count) matches shown above" } else{ Write-Host "Search completed with $($FoundGPOs.count) matches" } } } |