![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | regex help I'll be the first to say that I don't know jack about regex, and I need to. That aside, I am asking for assistance with a simple problem. When I use get-qaduser and check the MemberOf member, I would like to shorten its output to just show the group name only. For instance, here's my current, standard output: [PS] C:\>$b.MemberOf -match "G-" CN=g-MKT Sales Operations Book,OU=g - global groups,OU=Sales,OU=Marketing,OU=Security Group Admin,OU=Information Protec tion,OU=ABC - Corporate Applications,DC=abc,DC=corp,DC=company,DC=com CN=g-ABCFIL22 Users,OU=g - global groups,OU=Marketing,OU=Security Group Admin,OU=Information Protection,OU=ABC - Cor porate Applications,DC=abc,DC=corp,DC=company,DC=com And I'd like to have it output this instead: CN=g-MKT Sales Operations Book CN=g-ABCFIL22 Users Thus, I only need the text up until the first comma in the text. Any help is appreciated. Also, and good easy-to-understand regex learning resource would be helpful! -Jason |
My System Specs![]() |
| | #2 (permalink) |
| | RE: regex help Hi Jason, I can't test any AD code but can help with the RegEx. Use the -Replace operator to capture and replace all chars up to the first comma: # mind word wrap $strArray = 'CN=g-MKT Sales Operations Book,OU=g - global groups,OU=Sales,OU=Marketing,OU=Security Group Admin,OU=Information Protection,OU=ABC - Corporate Applications,DC=abc,DC=corp,DC=company,DC=com', 'CN=g-ABCFIL22 Users,OU=g - global groups,OU=Marketing,OU=Security Group Admin,OU=Information Protection,OU=ABC - Corporate Applications,DC=abc,DC=corp,DC=company,DC=com' $strArray -replace '([^,]+).+','$1' # here's another way $strArray | % {$_.split(',')[0]} I'd recommend this site, it's a great tutorial on RegEx: http://www.regular-expressions.info/tutorialcnt.html -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: regex help On Oct 13, 10:29*am, Jason <Ja...@xxxxxx> wrote: Quote: > I'll be the first to say that I don't know jack about regex, and I need to. * > That aside, I am asking for assistance with a simple problem. > > When I use get-qaduser and check the MemberOf member, I would like to > shorten its output to just show the group name only. * > > For instance, here's my current, standard output: > [PS] C:\>$b.MemberOf -match "G-" > CN=g-MKT Sales Operations Book,OU=g - global > groups,OU=Sales,OU=Marketing,OU=Security Group Admin,OU=Information Protec > tion,OU=ABC - Corporate Applications,DC=abc,DC=corp,DC=company,DC=com > CN=g-ABCFIL22 Users,OU=g - global groups,OU=Marketing,OU=SecurityGroup > Admin,OU=Information Protection,OU=ABC - Cor > porate Applications,DC=abc,DC=corp,DC=company,DC=com > > And I'd like to have it output this instead: > CN=g-MKT Sales Operations Book > CN=g-ABCFIL22 Users > > Thus, I only need the text up until the first comma in the text. > > Any help is appreciated. *Also, and good easy-to-understand regex learning > resource would be helpful! > > -Jason '$[^,]+' But your case doens't eve need to mess with that. You can split on comma and select the first group by it's index. $a = 'text containing, comma seperated, text' ($a.split(','))[0] Or simply select the substring up to the comma $a.substring(0,$a.indexof(',')) |
My System Specs![]() |
| | #4 (permalink) |
| | Re: regex help Hello Jason, if you want a really good RegEx tool, I would strongly recommend buying RegexBuddy. It's worth every penny. And a lot better than the freeware ones you can find (at least I think so, and I gained much from it, still do, when I had to learn Regular Expressions). Anyway... That aside, I think there's a much simpler solution to your problem, than dabbling with regexes. "CN=($b.MemberOf -match "G-").name" Simply put, create a string that starts with CN=, and then expand the name of the group and put if after CN=. Of course, you need to do a for each loop to do it for each group you find, but that's pretty simple too. Just thought it was a bit more pragmatic than regexes, and wanted to present another solution to your problem ![]() (Bear in mind I haven't tested the specific code, am in a bit of a hurry here, but the principle should work just fine). -- Kind Regards, Jacob Saaby Nielsen http://www.ijacob.info PowerShell trouble ? http://www.powershellcommunity.org Quote: > I'll be the first to say that I don't know jack about regex, and I > need to. That aside, I am asking for assistance with a simple > problem. > > When I use get-qaduser and check the MemberOf member, I would like to > shorten its output to just show the group name only. > > For instance, here's my current, standard output: > [PS] C:\>$b.MemberOf -match "G-" > CN=g-MKT Sales Operations Book,OU=g - global > groups,OU=Sales,OU=Marketing,OU=Security Group Admin,OU=Information > Protec > tion,OU=ABC - Corporate Applications,DC=abc,DC=corp,DC=company,DC=com > CN=g-ABCFIL22 Users,OU=g - global groups,OU=Marketing,OU=Security > Group > Admin,OU=Information Protection,OU=ABC - Cor > porate Applications,DC=abc,DC=corp,DC=company,DC=com > And I'd like to have it output this instead: > CN=g-MKT Sales Operations Book > CN=g-ABCFIL22 Users > Thus, I only need the text up until the first comma in the text. > > Any help is appreciated. Also, and good easy-to-understand regex > learning resource would be helpful! > > -Jason > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Regex help please? | PowerShell | |||
| regex help | PowerShell | |||
| Regex Help | PowerShell | |||
| Regex Help | .NET General | |||
| regex | PowerShell | |||