Group Policy details along with OU details

 

This script will provide the GPO name and organization unit name where the respective group policy is linked.

This script extract the Organizational unit information along with LinkedGroupPolicyObjects details. From LinkedGroupPolicyObjects it will query for GPO name using GUID. This script will make simple txt file from where you can copy to csv and delimited with ";" to get full report

null
Edit|Remove
$policies = Get-ADOrganizationalUnit -Filter * -properties * |select name,DistinguishedName,LinkedGroupPolicyObjects


$policies | % { 
                $name = $null
                $DistinguishedName = $null
                $LinkedGPOs = $null
                $name = $_.name
                $DistinguishedName = $_.DistinguishedName
                $LinkedGPOs = $_.LinkedGroupPolicyObjects
                foreach($LinkedGPO in $LinkedGPOs)
                        {
                        $r = $null
                        $r1 = $null
                        $r2 = $null
                        $r3 = $null
                        $r4 = $null
                        $r5 = $null
                        $t = $null
                        $msg = $null
                        $r = $LinkedGPO
                        $r1 = $r.Split(",")
                        $r2 = $r1[0]
                        $r3 = $r2.Replace("cn={","")
                        $r4 = $r3.Replace("}","")
                        $r5 = $r4.Replace("CN={","")
                        $t = get-gpo -Guid $r5
                        $msg = $t.displayname + ";" + $name + ";" + $DistinguishedName
$msg
                        $msg >>out.txt
                        }
}