Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Grabbing text in an array between two characters

$
0
0

I have an array of text that contains group memberships for users. Each item in the array is the DN of the group. I want to be able to select everything for each object in the array that looks like "CN=somegroupname,", remove the "CN=" and repalce the "," with a ";". This way after running I'll have a list for each user that I can have the helpdesk copy and paste the text back in to AD to restore the group memberships. 

For example...

Before:

John Doe
CN=GroupA-abc-def,OU=Groups,DC=xyz,DC=com

CN=GroupB-abc-def,OU=Groups,DC=xyz,DC=com

CN=GroupC-abc-de-,OU=Groups,DC=xyz,DC=com

After:

GroupA-abc-def;GroupB-abc-def;GroupC-abc-def

I've been playing with -join/split but I can't seem to find the right syntax to grab all the text between CN= and ,



Viewing all articles
Browse latest Browse all 21975

Trending Articles



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