Avatar of IT _Admin0723
IT _Admin0723
Flag for United States of America asked on

Get GPOs linked to Specific Parent OU and its Child OU

Hello PS experts,

This seems a challenge and wondering if anyone has a handy script on how to get GPOs linked to a specific OU (CN=Hello,DC=contoso,DC=com) and its child domains and pipe it to a csv output file. Tried different ways and not successful.

Please help!

Thank you so much.
Powershell

Avatar of undefined
Last Comment
Ben Personick (Previously QCubed)

8/22/2022 - Mon
Shaun Vermaak

You cannot link GPOs to a container (CN=Hello,DC=contoso,DC=com), did you mean OU (OU=Hello,DC=contoso,DC=com)?

and its child domains
Also, did you mean child OUs? This is automatic if inheritance block is not enabled or enforce is configured on GPO
SOLUTION
Ben Personick (Previously QCubed)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
IT _Admin0723

ASKER
Sorry I meant OU=hello,dc=contoso,dc=com
IT _Admin0723

ASKER
@Ben Personick it is complex indeed. I came across that script as well (2nd version), tried it and had to change $server variable to a dc=child,dc=contoso,dc=com as we have multiple child domains in our environment but for some reason it came back blank (no results)?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Kevin Stanush

You can use Hyena's 30-day trial to do this and have 29 3/4 days to spare in the eval.  Select the OUs (one or more), right click, and select the Linked Policies view.  It will show any OU attribute, along with any linked policy information in the directory.
Ben Personick (Previously QCubed)

Seems like this guys' script is all; sorts of wrong, not my first time experiencing that in technet.

I have gotten as far as enumerating all the OUs and getting linked GPOs for each, but now it's not sorted, and I have to re-package it into a new object but I need to head out for a bit this is 90% of your needs, but still very rough, sorry I will come back to it later, or another expert might clean it up before I get to it, but this should be the guts now.

Function Get-ADOrganizationalUnitOneLevel {            
param($Path_ADOUOL, $Server_ADOUOL)#, $OUHash_ADOUOL)       
    #write-output "Path_ADOUOL '$Path_ADOUOL'"
    #write-output "Path_ADOU '$Path_ADOU'"
    #write-output "Server_ADOUOL '$Server_ADOUOL'"
    #write-output "Server_ADOU '$Server_ADOU'"
    Get-ADOrganizationalUnit -Filter * -Properties name, distinguishedName, gPLink, gPOptions -SearchBase $Path_ADOUOL -SearchScope OneLevel | Sort-Object Name | ForEach-Object {            
        #$script:OUHash.Add($_.DistinguishedName,$script:Counter++)
        
        
         ## HERE Create New PS Object and then output that to cli so it will be caught by the original.
        
        $DistinguishedName = $_.DistinguishedName
        $gPLink = $_.gPLink
        $gPOptions = $_.gPOptions
        ## Regular outoput for now
        $DistinguishedName
        $gPLink
        $gPOptions
        Get-ADOrganizationalUnitOneLevel -Path $_.DistinguishedName

    }
}            
            
Function Get-ADOrganizationalUnitSorted {  
param($Server_ADOU)          
    $DomainRoot = (Get-ADDomain -Server $Server_ADOU).DistinguishedName            
    #write-output "DomainRoot '$DomainRoot'"
    #write-output "Server_ADOU '$Server_ADOU'"
    #$script:Counter = 1            
    #$script:OUHash = @{$DomainRoot=0}            
    Get-ADOrganizationalUnitOneLevel $DomainRoot $Server_ADOU $OUHash

            
   #$OUHash            
}            
$Server = 'sub.domain.com'

$SortedOUs = Get-ADOrganizationalUnitSorted $Server
$SortedOUs

Open in new window

ASKER CERTIFIED SOLUTION
Ben Personick (Previously QCubed)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.