logo powershell

Zoeken in GPO’s

Wanneer je even niet met de group policy results wizard overweg kunt, is er toch een methode om te zoeken in de GPO’s. Met het onderstaande Powershell script doorzoek je alle policies.

$String = "Zoekterm"
$Domain = "jouwdomein.local"

$NearestDC = (Get-ADDomainController -Discover -NextClosestSite).Name

#Get a list of GPOs from the domain
$GPOs = Get-GPO -All -Domain $Domain -Server $NearestDC | sort DisplayName

#Go through each Object and check its XML against $String
Foreach ($GPO in $GPOs)  {
  
  Write-Host "Zoeken in $($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
  }
  
}