Link to home
Start Free TrialLog in
Avatar of IT _Admin0723
IT _Admin0723Flag for United States of America

asked on

Query GPOs linked to OUs Powershell

Hello experts,

I would like to query GPOs linked to  multiple OUs (in DN format) from a file format. I have the following simple array below but would like to ask for your expertise on how to pipe the following results to the following format (columns) to a file.

Column A = OU/DN
Column B = GPO name
Column C = GPO GUID
Column D = Enforced

PS Script:

SDN= Get-Content c:\temp\listofDNsofOUs.txt

Foreach ($DN in $DNs)

(
(Get-GPInheritance -target $dn).gpolinks;
}

Thank you so much!
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IT _Admin0723

ASKER

Thank you! I tweaked it  a little bit to below because it was erroring stating an empty pipe element is not allowed. This is exactly what i need. Thanks so much!

$DNs = Get-Content c:\temp\listofDNsofOUs.txt
$(ForEach ($DN In $DNs) {
      Get-GPInheritance -Target $DN |
            Select-Object -ExpandProperty GPOLinks |
            Select-Object @{n='DN'; e={$DN}}, DisplayName, GpoId, Enforced, Order |
            Sort-Object -Property Order
}
)| Export-Csv -NoTypeInformation -Path C:\Temp\GPOLinks.csv