Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > string manipulation in vbs or vb.net

Reply
Thread Tools Display Modes

string manipulation in vbs or vb.net

 
 
Jesper Ravn
Guest
Posts: n/a

 
      11-09-2009
Hello

Im retriving users out from a security group in Active Directory.
The output is like the string below.

StrMember = "CN=ctxadmin,OU=ITservices,OU=RootDomain,DC=compan y,DC=com"

How can I clean the string, so it always will list only the username.
StrMember = "ctxadmin"

Thanks,

/Jesper
 
Reply With Quote
 
 
 
 
Jesper Ravn
Guest
Posts: n/a

 
      11-09-2009



"Tom Lavedas" <> skrev i meddelelsen
news:504bfc02-1ca4-482f-a4b5-...
> On Nov 9, 5:57 am, "Jesper Ravn" <jesper_r...@hotmail.com> wrote:
>> Hello
>>
>> Im retriving users out from a security group in Active Directory.
>> The output is like the string below.
>>
>> StrMember = "CN=ctxadmin,OU=ITservices,OU=RootDomain,DC=compan y,DC=com"
>>
>> How can I clean the string, so it always will list only the username.
>> StrMember = "ctxadmin"
>>
>> Thanks,
>>
>> /Jesper

>
> Maybe ...
>
> StrMember =
> "CN=ctxadmin,OU=ITservices,OU=RootDomain,DC=compan y,DC=com"
> strMember=Replace(Split(strMember. ",")(0), "CN=", "", -1, 1)


Hi Tom

Thanks, for your suggestion, but the code sample fails. I also tried to
change "StrMember. " to "StrMember," without any luck.
I just ran the code in a VBScript file.

/Jesper

 
Reply With Quote
 
Jesper Ravn
Guest
Posts: n/a

 
      11-09-2009

"Tom Lavedas" <> skrev i meddelelsen
news:a59ec48a-62f6-49dc-8ec4-...
> Sorry, I did that from memory and without testing. There is a typo
> and a missing argument (which you could have researched), but the
> concept is valid. Try this ..
>
> strMember = Replace(Split(strMember, ",")(0), "CN=", "", 1, -1, 1)


Hi Tom

Great, it's working now. Thanks a lot.

/Jesper

 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      11-09-2009


"Jesper Ravn" <> wrote in message
news:...
>
> "Tom Lavedas" <> skrev i meddelelsen
> news:a59ec48a-62f6-49dc-8ec4-...
>> Sorry, I did that from memory and without testing. There is a typo
>> and a missing argument (which you could have researched), but the
>> concept is valid. Try this ..
>>
>> strMember = Replace(Split(strMember, ",")(0), "CN=", "", 1, -1, 1)

>
> Hi Tom
>
> Great, it's working now. Thanks a lot.
>
> /Jesper


However, note that the result is the "Common Name" of the user, not what
most people call the username, unless the two values have been made always
the same in your environment.

The value of the "cn" attribute is the Common Name of the object. It must be
unique in the OU, but there can be several objects with the same Common Name
as long as they are in different OU's or containers. The value of the
sAMAccountName attribute is the "pre-Windows 2000 logon name" (on the
"Account" tab of ADUC). This is also referred to as the userID, username, or
NT name of the user. This must be unique in the domain.

If the cn and sAMAccountName attributes are always the same in your domain,
you can parse the Distinguished Name of the user. Otherwise, you should use
the NameTranslate object to convert the Distinguished Name into the
sAMAccountName. See this link for details:

http://www.rlmueller.net/NameTranslateFAQ.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Jesper Ravn
Guest
Posts: n/a

 
      11-09-2009



"Richard Mueller [MVP]" <rlmueller-> skrev i
meddelelsen news:#...

> However, note that the result is the "Common Name" of the user, not what
> most people call the username, unless the two values have been made always
> the same in your environment.
>
> The value of the "cn" attribute is the Common Name of the object. It must
> be unique in the OU, but there can be several objects with the same Common
> Name as long as they are in different OU's or containers. The value of the
> sAMAccountName attribute is the "pre-Windows 2000 logon name" (on the
> "Account" tab of ADUC). This is also referred to as the userID, username,
> or NT name of the user. This must be unique in the domain.
>
> If the cn and sAMAccountName attributes are always the same in your
> domain, you can parse the Distinguished Name of the user. Otherwise, you
> should use the NameTranslate object to convert the Distinguished Name into
> the sAMAccountName. See this link for details:
>
> http://www.rlmueller.net/NameTranslateFAQ.htm


Hi Richard

Thanks for the heads up. I will take a look at your great FAQ ressource.

/Jesper

 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      11-09-2009

"Jesper Ravn" <> wrote in message
news:...
>
>
> "Richard Mueller [MVP]" <rlmueller-> skrev i
> meddelelsen news:#...
>
>> However, note that the result is the "Common Name" of the user, not what
>> most people call the username, unless the two values have been made
>> always the same in your environment.
>>
>> The value of the "cn" attribute is the Common Name of the object. It must
>> be unique in the OU, but there can be several objects with the same
>> Common Name as long as they are in different OU's or containers. The
>> value of the sAMAccountName attribute is the "pre-Windows 2000 logon
>> name" (on the "Account" tab of ADUC). This is also referred to as the
>> userID, username, or NT name of the user. This must be unique in the
>> domain.
>>
>> If the cn and sAMAccountName attributes are always the same in your
>> domain, you can parse the Distinguished Name of the user. Otherwise, you
>> should use the NameTranslate object to convert the Distinguished Name
>> into the sAMAccountName. See this link for details:
>>
>> http://www.rlmueller.net/NameTranslateFAQ.htm

>
> Hi Richard
>
> Thanks for the heads up. I will take a look at your great FAQ ressource.
>
> /Jesper


A quick example converting a DN into sAMAccountName:
========
Option Explicit

Dim strUserDN, objTrans, strUserName

' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify user Distinguished Name.
strUserDN = "CN=ctxadmin,OU=ITservices,OU=RootDomain,DC=compan y,DC=com"

' Use the NameTranslate object to convert Distinguished Name
' into sAMAccountName.
Set objTrans = CreateObject("NameTranslate")

' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Use the Set method to specify the Distinguished Name of the object.
objTrans.Set ADS_NAME_TYPE_1779, strUserDN
' Use the Get method to retrieve the NT format of the name.
' This format is <NetBIOS-Domain-Name>\<sAMAccountName>
strUserName = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove NetBIOS name of domain.
strUserName = Mid(strUserName, InStr(strUserName, "\") + 1)

Wscript.Echo strUserName

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Jesper Ravn
Guest
Posts: n/a

 
      11-10-2009

"Richard Mueller [MVP]" <rlmueller-> skrev i
meddelelsen news:...
>
> A quick example converting a DN into sAMAccountName:
> ========
> Option Explicit
>
> Dim strUserDN, objTrans, strUserName
>
> ' Constants for the NameTranslate object.
> Const ADS_NAME_INITTYPE_GC = 3
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
> ' Specify user Distinguished Name.
> strUserDN = "CN=ctxadmin,OU=ITservices,OU=RootDomain,DC=compan y,DC=com"
>
> ' Use the NameTranslate object to convert Distinguished Name
> ' into sAMAccountName.
> Set objTrans = CreateObject("NameTranslate")
>
> ' Initialize NameTranslate by locating the Global Catalog.
> objTrans.Init ADS_NAME_INITTYPE_GC, ""
> ' Use the Set method to specify the Distinguished Name of the object.
> objTrans.Set ADS_NAME_TYPE_1779, strUserDN
> ' Use the Get method to retrieve the NT format of the name.
> ' This format is <NetBIOS-Domain-Name>\<sAMAccountName>
> strUserName = objTrans.Get(ADS_NAME_TYPE_NT4)
> ' Remove NetBIOS name of domain.
> strUserName = Mid(strUserName, InStr(strUserName, "\") + 1)
>
> Wscript.Echo strUserName


Hi Richard

Nice, thanks for all your help.

/Jesper

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching all files in a folder for a string. Just Askin Windows Vista File Management 4 07-26-2009 06:07 PM
Disable File Copy in VB.NET BARDILL ActiveSync 1 03-14-2008 01:30 AM
Windows Vista Local Machine security policy Error 65 Help String S Chris Hyun Windows Vista Administration 1 02-26-2007 03:24 AM
Re: Registry Fix for MS Money 2006 and MS Money for PocketPC 2006 in Windows Vista with Windows Mobile Device Center Gary Waliczek [MSFT] ActiveSync 0 02-20-2007 10:46 PM
Re: Passthrough Agent string? Carl Wolz [MSFT] ActiveSync 1 11-20-2005 05:37 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59