'----------------------------------------------------------------
' comment: obtain object handle to RootDSE of domain
'----------------------------------------------------------------
Set objRootDSE = GetObject("LDAP://rootDSE")
'----------------------------------------------------------------
' comment: query for LDAP domain DN (eg. DC=domain,DC=com)
'----------------------------------------------------------------
LDAP_DN = Domain_LDAP()
ADSI_DN = Domain_NetBIOS(LDAP_DN)
'----------------------------------------------------------------
Function Domain_LDAP()
Domain_LDAP = objRootDSE.Get("defaultNamingContext")
End Function
'----------------------------------------------------------------
Function Domain_NetBIOS(ldapdn)
Domain_NetBIOS = Replace(Replace(ldapdn,"DC=",""),",",".")
End Function
So, anywhere in your vast array of VBscript files where you're querying Active Directory for information, and you have the LDAP string hard-coded, just replace it with the junk above and your code is instantly portable! Instantly! Just add hot water and stir. Makes its own sauce.
1 comment:
I had to edit this post to correct a small glitch in the code. The line that sets objRootDSE requires enclosing double-quotes as well as removing the trailing forward-slash. So GetObject(ldap://rootDSE/) should have been GetObject("LDAP://rootDSE") Sorry if that caused anyone some angst.
Post a Comment