Solved

PowerShell 2.0 Regex Distinguished Names.

Posted on 2014-11-05
2
296 Views
Last Modified: 2014-11-05
Looking for a way to parse a string that contains multiple Distinguished Names to put the names into a separate array.
Example.

$String = "CN=John S. Smith*a,OU=Users,OU=Tier 8,OU=Admins,DC=fg,DC=ef,DC=na,DC=ORG CN=Joe D. Smith*a,OU=Users,OU=Tier 2,OU=Admins,DC=fd,DC=hd,DC=tv,DC=ORG"

to

$NewString ="CN=John S. Smith*a,OU=Users,OU=Tier 8,OU=Admins,DC=fg,DC=ef,DC=na,DC=ORG"
"CN=Joe D. Smith*a,OU=Users,OU=Tier 2,OU=Admins,DC=fd,DC=hd,DC=tv,DC=ORG"
0
Comment
Question by:Xytras1
2 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 40425002
Try this.
$NewString = $String -split "CN=" | ? {$_} | % {"CN=$($_.trim())"}

Open in new window

0
 

Author Closing Comment

by:Xytras1
ID: 40425011
Works great. Thank you.
0

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now