The below written script gives you information of all GPO’s linked to OU’s in your domain.
Get list of all OU's under the domain
$OUs = Get-ADOrganizationalUnit -Filter * -SearchBase "OU=OUName,DC=domain,DC=local" -Properties *
Variable Declaration
$__FinalGPOList = @()
Loop through each OU and get the linked GPO
foreach($OU in $OUs)
{
$__GPOLink = @{}
$__OUGPInheritance = Get-GPInheritance -Target $ou.DistinguishedName
$__GPOLink = $__OUGPInheritance | select -ExpandProperty GpoLinks |
select @{Name = "GPOName"; Expression = {$_.DisplayName}}, @{Name = "OU_DN"; Expression = {$_.Target}}, Order, Enabled
Along with the GPO name, OU Distinguished Name, Link Order and Enabled status, below code gives details
of OU canonical name and OU inheritance details.
$__GPOLink | % { $_ | Add-Member -MemberType NoteProperty -Name OU -Value $OU.CanonicalName } $__GPOLink | % { $_ | Add-Member -MemberType NoteProperty -Name InheritanceBlocked -Value $__OUGPInheritance.GpoInheritanceBlocked } $__GPOLink $__FinalGPOList += $__GPOLink
}
$__FinalGPOList | select OU, GPOName, Order, InheritanceBlocked, Enabled | Export-Csv C:\Users\admin\Desktop\gpo.csv -NoTypeInformation
Thank you for reading my post and hope it is helpful to you.
Recent Comments