asp classic - VBscript search sAMAccountName from CN -
i've written script pulls samaccountname of specified user ad via vbscript, seems work within own ou group. due permissions restriction within company? or due i'm not seeing in code?
dim result result = getsamaccountname("samuel j link") msgbox result
function getsamaccountname(name) dim adocommand, adoconnection, strbase, strfilter, strattributes dim objrootdse, strdnsdomain, strquery, adorecordset, strsam, objuser set adocommand = createobject("adodb.command") set adoconnection = createobject("adodb.connection") adoconnection.provider = "adsdsoobject" adoconnection.open "active directory provider" set adocommand.activeconnection = adoconnection set objrootdse = getobject("ldap://rootdse") strdnsdomain = objrootdse.get("defaultnamingcontext") msgbox strdnsdomain strbase = "<ldap://" & strdnsdomain & ">" 'be sure passed var usersel referenced strfilter = "(cn=" & name & ")" strattributes = "distinguishedname" strquery = strbase & ";" & strfilter & ";" & strattributes & ";subtree" adocommand.commandtext = strquery adocommand.properties("page size") = 100 adocommand.properties("timeout") = 30 adocommand.properties("cache results") = false set adorecordset = adocommand.execute until adorecordset.eof strsam = adorecordset.fields("distinguishedname").value set objuser = getobject("ldap://" & strsam) getsamaccountname = objuser.samaccountname adorecordset.movenext loop adorecordset.close adoconnection.close end function
does work when specify ou in getobject call?
getobject("ldap://ou=yourou,dc=yourdomain,dc=com")
from question querying active directory using vbscript
Comments
Post a Comment