Query AD Security membership and spilt results

Hi,

I have a VBS script that list to a text file all AD security groups that user is member of. Problem is that query returns full distinguished name like "CN=Citrix MS Access 97,OU=CTX_application_groups,OU=Fi,OU=Groups,OU=company,DC=domain,DC=domain,DC=com"

For the sake of simplicity I would like to spilt this and write only the name of the group to the user who will eventually use this data

Where it gets complicated (to me) is that some of our group names also contain , (comma). So if I just use "MyArray = Split(Group, ",", -1, 1)" it splits also the group name.

Any way around this?

Thanks!

June 28th, 2013 12:50pm

It would probably be better to modify the script that got you this information from AD in the first place.  Each group has an attribute called "sAMAccountName", which is the short name of the group that you see in the DOMAIN\Group format (and is not necessarily guaranteed to match the CN of the group in the distinguished name).

Free Windows Admin Tool Kit Click here and download it now
June 28th, 2013 2:38pm

Hi,

What I generally do in this situation is use InStr to find the position of the first occurrence of "OU=".  I'll then use Mid to return only the needed portion of the distinguishedName string. Here's a quick example:

strDN = "CN=Citrix MS Access 97,OU=CTX_application_groups,OU=Fi,OU=Groups,OU=company,DC=domain,DC=domain,DC=com"

nameOnly = Mid(strDN,4,InStr(strDN,"OU=")-5)

MsgBox nameOnly

June 28th, 2013 4:09pm

Hi,

What I generally do in this situation is use InStr to find the position of the first occurrence of "OU=".  I'll then use Mid to return only the needed portion of the distinguishedName string. Here's a quick example:

strDN = "CN=Citrix MS Access 97,OU=CTX_application_groups,OU=Fi,OU=Groups,OU=company,DC=domain,DC=domain,DC=com"

nameOnly = Mid(strDN,4,InStr(strDN,"OU=")-5)

MsgBox nameOnly

 So now you see why the suggestion was made to go to AD to get the info.  There are too many string conditions that will defeat your attempt.

This will accurately get you what you want.

Set obj = GetObject("LDAP://" & strDN)

WScript.Echo obj.CN

Two lines no ambiguity.

Free Windows Admin Tool Kit Click here and download it now
June 29th, 2013 4:17am

 So now you see why the suggestion was made to go to AD to get the info.  There are too many string conditions that will defeat your attempt.

This will accurately get you what you want.

Set obj = GetObject("LDAP://" & strDN)

WScript.Echo obj.CN

Two lines no ambi

June 29th, 2013 5:32am

So doing something the right way is cheating now?  Very interesting.

Since you are so interested in doing it the had way we will let you figure out how to design a RegEx that can apply all the rules you need to do this.  I can do it.  Can you?

Use the object.  That is what it is there for,

Free Windows Admin Tool Kit Click here and download it now
June 29th, 2013 5:36am

By the way.. Mike likes to do the impossible.

June 29th, 2013 5:37am

So doing something the right way is cheating now?  Very interesting.

Since you are so interested in doing it the had way we will let you figure out how to design a RegEx that can apply all the rules you need to do this.  I can do it.  Can you?

Use the object.  That is what it is ther

Free Windows Admin Tool Kit Click here and download it now
June 29th, 2013 5:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics