$ADS_SCOPE_SUBTREE = 2
$objConnection = CreateObject('ADODB.Connection')
$objCommand = CreateObject('ADODB.Command')
$objConnection.Provider = 'ADsDSOObject'
$objConnection.Open('Active Directory Provider')
$objCommand.ActiveConnection = $objConnection
$DN=GetUserDN("")
? $DN
$strBase = "<LDAP://" + $DN + ">"
$strFilter = "(&(objectCategory=person)(objectClass=user))"
$strAtt="distinguishedName, canonicalName, cn, employeeID, department"
$strQuery = $strBase + ";" + $strFilter + ";" + $strAtt + ";subtree"
$objCommand.CommandText=$strQuery
$objRecordSet = $objCommand.Execute()
$CanonicalName=Join($objRecordSet.Fields("canonicalName").Value)
? $CanonicalName
Function getUserDN(optional $username)
Dim $objTrans
if $username=""
$username=@ldomain + "\"+ @userid
endif
if not instr($username,"\")
$username=@ldomain + "\" + $username
endif
$objTrans = CreateObject("NameTranslate")
if @error
exit @error
else
$objTrans.Init(3, "")
$objTrans.Set(3,$username)
$getUserDN = $objTrans.Get(1)
if @error
exit @error
endif
endif
EndFunction