Get GPOs linked to an OU

Get the OU first
Microsoft AD module

$dn = Get-ADObject -Filter {name -like "OU name*"} | select -expand distinguishedname


Get-ADOrganizationalUnit -Filter {name -eq "OU_Name"} 


Get-ADOrganizationalUnit -Identity OU_DistinguishedName 

Quest AD Commandlets

Get-QADObject -Name "Domain Controllers" -Type organizationalUnit

The type parameter makes Get-QADobject search for objects that have one of the objectClass attribute values set to the Type parameter value

Get the GPO links

(Get-GPInheritance -Target $dn).gpolinks

Get GPO Objects

Once we have GPO links we get GPO guids from them and use these to get the GPOs

Get-ADOrganizationalUnit -Filter {name -eq "OU_Name"} | Select-Object -expand distinguishedname | Get-GPInheritance | Select-Object -expand gpolinks | ForEach-Object {get-gpo -Guid $_.gpoid}

or we can use the LinkedGroupPolicyObjects property, find a GPO GUID in there using regex (notice the named group gpoguid, also notice how we access that named group inside the Matchinfo objects returned by Select-String)

Get-ADOrganizationalUnit -Identity "OU=GFŘ,DC=cb,DC=ds,DC=mfcr,DC=cz" | select -ExpandProperty LinkedGroupPolicyObjects | Select-String -Pattern "^cn={(?<gpoguid>.*)}.*" | select -ExpandProperty matches | ForEach-Object {$GpoGuid = $_.Groups["gpoguid"].value;get-gpo -Guid $GpoGuid}

Tagged: ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Tips, tricks and time-savers for the Windows and ConfigMgr administrator

To The Point

Anything about Technology and Business

Brian's Power Windows Blog

Microsoft in the Enterprise. Windows, Hyper-V, Exchange, SQL, and more!

PowerScripting Podcast

Shownotes and links for the PowerScripting Podcast, a podcast to help people learn Windows Powershell

Learn Powershell | Achieve More

What is this Powershell of which you speak?

%d bloggers like this: