10 May, 2009

How to get the DN from an NT name...

Hi,

If you are scripting you may came across the annoying problem of the DN name.
In everyday activity you use the NT name of an object from Active Directory but when you want to start scripting - no... you need the DN.

The following Script will help you convert on the fly the NT name to DN object.

===================================
private function TranslateNTName(ntname)
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
TranslateNTName=""
set nto = CreateObject("NameTranslate")
'on error resume next
nto.Init ADS_NAME_INITTYPE_GC , ""
nto.set ADS_NAME_TYPE_NT4, ntname
TranslateNTName = nto.Get(ADS_NAME_TYPE_1779)
on error goto 0
end function

wscript.echo TranslateNT4Name ("domain\user")
===================================

Enjoy

No comments:

Post a Comment