One option might be to use “-split”: PS U:\> $a = "OU=MyHouse,OU=World,DC=domain,DC=net" PS U:\> ($a -split ",")[0] OU=MyHouse PS U:\> (($a -split ",")[0] -split "=")[1] MyHouse
Edward From: [email protected] [mailto:[email protected]] On Behalf Of Dave Lum Sent: Wednesday, November 02, 2016 3:45 PM To: '[email protected]' Subject: [NTSysADM] PowerShell Help I want to use PowerShell to get the immediate OU a user is in an drop it into said users’ description. I can do Set-ADUSer easily enough, I just want to be able to through only the direct OU and not the entire DN into the description. So, instead of 'OU=MyHouse,OU=World,DC=domain,DC=net' I want to just drop in “MyHouse” (the desired description will me “disabled account from myHouse OU”. Some “ForEach” thing, right? David Lum Systems Administrator III P: 503.943.2500 E: [email protected]<mailto:[email protected]> A: 1881 SW Naito Parkway, Portland, OR 97201 [Facebook Link]<https://www.facebook.com/OCHINinc>[Twitter Link]<https://twitter.com/ochininc>[Linkedin Link]<http://www.linkedin.com/company/ochin> www.ochin.org<https://www.ochin.org/> [OCHIN email] Attention: Information contained in this message and or attachments is intended only for the recipient(s) named above and may contain confidential and or privileged material that is protected under State or Federal law. If you are not the intended recipient, any disclosure, copying, distribution or action taken on it is prohibited. If you believe you have received this email in error, please contact the sender with a copy to [email protected]<mailto:[email protected]>, delete this email and destroy all copies.

