#PSTip Show friendly GPO names with Get-ADOrganizationalUnit

When using the Get-ADOrganizationalUnit cmdlet there is a property available, LinkedGroupPolicyObjects. Unfortunately, that property only displays the GUID of the Group Policy Objects. To make it easier to identify which GPOs are linked to an Organizational Unit the following function will gather the display names for these GPOs and place the names of the GPOs in a new property named ‘FriendlyGPODisplayName’:

Funtion Get-OUWithGPOLink {
   Get-ADOrganizationalUnit -Filter "Name –like '*'" -Properties name, distinguishedName, gpLink |
   Select-Object -Property *, @{
       Name = 'FriendlyGPODisplayName'
       Expression = {
           $_.LinkedGroupPolicyObjects | ForEach-Object {
             -join ([adsi]"LDAP://$_").displayName

To illustrate what this means in practice I have included the difference between the output of Get-ADOrganizationalUnit and Get-OUWithGPOLink:


Please note that this function still requires the PowerShell Active Directory module to be present on the system. The function utilizes ADSI to connect to the ADObject of the GPO to get the DisplayName value. The display names are made available by utilizing Select-Object with a calculated property.

The full version of this function is available and will be maintained in the TechNet Script Gallery, available here.

About the author: Jaap Brasser

Jaap is a Senior System Engineer in the Financial Services industry. He focuses on Microsoft and related technologies and has a passion for PowerShell. In his spare time he maintains his Blog, Twitter feed, @Jaap_Brasser, and contributes on the Official Scripting Guys Forum and Windows PowerShell TechNet forums

Related Posts