how to find a user and bind using vbscript

  • Thread starter Thread starter Tejas PArikh
  • Start date Start date
T

Tejas PArikh

Hey, Can someone explain the syntax of the finding an
object in AD and explain how to find a user given the
username or the samaccountName and then finding which ou
it exists in and then bind to it and perform some
modifications to the account? I want to use vbscript in
order to do this. I'll be very thankful for your help.
 
The easiest way is to use the nametranslate and then bind to the DN returned

Here is a nametranslate routine you can use

'
' Translate NT4 names to dn
'
private function TranslateNT4Name(nt4name)
dim nto
dim result
const ADS_NAME_INITTYPE_SERVER = 2
const ADS_NAME_INITTYPE_GC = 3
const ADS_NAME_TYPE_1779 = 1
const ADS_NAME_TYPE_NT4 = 3

TranslateNT4Name=""
set nto = CreateObject("NameTranslate")
on error resume next
nto.Init ADS_NAME_INITTYPE_GC , ""
if err then
wscript.echo
wscript.echo "ERROR: Couldn't create name translate object."
end if
nto.set ADS_NAME_TYPE_NT4, nt4name
'
' If this fails we want it to just return a blank value
'
TranslateNT4Name = nto.Get(ADS_NAME_TYPE_1779)
on error goto 0
end function



The DN that is returned can be bound to with

set o=getobject("LDAP://" & dn)
 
Back
Top