Wednesday , October 16 2024
Home - Development - Easy Find OU in a DistinguishedName with PowerShell

Easy Find OU in a DistinguishedName with PowerShell

There are a couple of ways to find the OU of an Object, some are long-winded ways splitting and counting characters.  The best way I’ve come up with for a quick and case insensitive check:

A better example of the use in code:

The Case Culture fixes up the compare of string being a different case of “OU=”, otherwise it may fail depending on code use.  Notice the above example having the OU being in lower case for “ou=Corp” but it still matches “OU=Corp”.

This can also be used on a collection object adding a new column called the “ParentOU”.  The following example show how to get a build $users with a list of users from the Domain but only shows two columns:

We can modify the collection to have an additional column with the following:

This results in the following collection format table:

Notice, the user objects in the Users Folder in Active Directory.  It’s a folder and not an Organisation Until so the ParentOU is blank.

To add the column to the collection object:

Check Also

Mac Outlook 2016 Screen/View Crashed and Flashing black

The Outlook 2016 client has been trusted workhorse for email since the full release.  However …

Leave a Reply

Your email address will not be published. Required fields are marked *