Richard Mueller [MVP] replied to Jesper Ravn
09-Nov-09 11:06 AM

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=company,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
--