top of page
Writer's pictureRattandeep singh

PwerShell! Split-Path



Have you ever split paths with anyting in your life. Once, I did with ice-creams. That was very painful till the time I did not start eating ice-cream again.


But, it may be helpful if you know, how to split an Organizational Unit (OU) path as an Active Directory (AD) administrator.


Consider a scenario, you need to share a list of the objects available in Active Directory with the Organizational Unit details it is available in. There are no direct attributes to show the Organizational Unit (OU) or the container as parent of the object. You can use Canonical Name or Distinguished Name to identify the same. However, that will have the object name as well.


How you can get the Organizational Unit (OU) path as value in your report?

Let's consider to use the attribute "CanonicalName" and extract the parent Organizational Unit (OU) or the container detail from it.


Here, I have stored the CanonicalName "Designbots.in\TestOU\Testuser1" in a variable. It has the object name as "TestUser1" at the end and "Designbots.in\TestOU" is the parent Organizational Unit (OU) along with the domain name.

I used "Split-Path" cmdlet to split it using the parameter "-Parent" allowing it to show the parent path only and ignore the object.










The ouput is..











Let's do the opposite now. We can get the object name and ignore the parent Organizational Unit (OU) details uisng the parameter "Leaf".










This time the output has only the end object name and the Organizational Unit (OU) path.










I hope this was informational and will save your time in extracting the Organizational Unit (OU) details.

Don't worry, I did not forget the Distinguished Name.

I will be writing one more blog to split the Distinguished Name as well. Stay tuned....





21 views0 comments

Comments


bottom of page