Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Questions about split ..trying to extract 2 levels of OUs from distinguishedname

$
0
0

Hallo .. I'm still on a voyage of self-discovery to teach myself Powershell. Be kind. 

I'd like to extract two levels of OU names from a computer object's distinguished name in AD for a report. I'm getting .distinguishedname from get-adcomputer.

I have this:  

        CN=COMPUTERNAME,OU=OU2,OU=OU1,OU=NOTWANTED,OU=NOTTHISEITHER,DC=FOO,DC=BAR,DC=COM

...and I'd like to pull out: 

       OU1
       OU2

I'd like each assigned to its own variable. Through messing around I've been able to get a little of what I want using split:

       $OU = ($blah.DistinguishedName -split ",*..=")[2,3]

This gives me both OU1 and OU2, but I can't figure out how to separate *that* into two separate values which I can assign to $OU1 & $OU2. 

Is split even the right choice, or would a regular expression be the way to go? I confess I don't really understand those yet. 

Examples would be welcome.

Thanks much. 
LW



Lanwench ** Do not fold, spindle or mutilate. Fill in the box completely and erase any stray marks. Use only a #2 pencil.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>