Find Group Policies linked to Active Directory OU Using PowerShell


Method 1: OU name like “test”

$LinkedGPOs = Get-ADOrganizationalUnit -Filter ‘Name -like “*test*”‘ | select -ExpandProperty LinkedGroupPolicyObjects
$GUIDRegex = “{[a-zA-Z0-9]{8}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{12}}”

foreach($LinkedGPO in $LinkedGPOs) {
$result = [Regex]::Match($LinkedGPO,$GUIDRegex);
if($result.Success) {
$GPOGuid = $result.Value.TrimStart(“{“).TrimEnd(“}”)
Get-GPO -Guid $GPOGuid
}

}


Method 2: Ou name test with path

$LinkedGPOs = Get-ADOrganizationalUnit -Identity “OU=test,DC=AA,DC=COM” | select -ExpandProperty LinkedGroupPolicyObjects
$GUIDRegex = “{[a-zA-Z0-9]{8}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{12}}”

foreach($LinkedGPO in $LinkedGPOs) {
$result = [Regex]::Match($LinkedGPO,$GUIDRegex);
if($result.Success) {
$GPOGuid = $result.Value.TrimStart(“{“).TrimEnd(“}”)
Get-GPO -Guid $GPOGuid
}

}

http://techibee.com/group-policies/find-group-policies-linked-to-active-directory-ou-using-powershell/2419

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: