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

How do I filter our parts of a string using powershell?

$
0
0

Hi all,

The goal I'm trying to accomplish is getting the DN of a user's object without any part of the CN= attribute using powershell.

For example, here's what I get for the DN of a user:

CN=Smith\, John (jsmith),OU=NewYork,OU=Users,DC=Example,DC=Com

I'm having trouble understanding how to filter out the text in the string in the beginning, which is the part that contains:

CN=Smith\, John (jsmith), 

All I want from the string is the OU=NewYork part.  I can handle stripping out the ,OU=Users,DC=Example,DC=Com using the replace function.  If all of my users had the same number of characters for their name, that would be easy.  But alas, that is obviously not the case.

The problem is that I have a csv file with many users, so the "prefix" where the CN= part is always going to be some variable length.  My idea was to somehow search the string for a match of  ), and then remove all text before that match.  But I don't know how to and apparently don't know the proper terminology to use to search on.

Any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



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