All-
I am trying to add on to a small script I saw posted by Richard
Mueller (www.rlmueller.net).
His script takes the current logged on user's logon name and
determines and displays the DN.
I am attempting instead to have the script read a list of logon names
(sam account names) and go out and determine the DN for each. Output
to be written to a results text file.
I am getting a type mismatch error and I can see the problem is
related to strNTName but I'm not sure how to correct it.
Here is Richard's script (this one works):
Set objNetwork = CreateObject("Wscript.Network")
strNTName = objNetwork.UserName
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use the NameTranslate object to find the NetBIOS domain name from
the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init 3, strDNSDomain
objTrans.Set 1, strDNSDomain
strNetBIOSDomain = objTrans.Get(3)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
objTrans.Init 1, strNetBIOSDomain
objTrans.Set 3, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(1)
Wscript.Echo "User DN: " & strUserDN
++++++++++++++++++
Here is the script I am attempting to get working (but not quite there
yet):
Const ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\results.txt", ForAppending, True)
'Opens existing file for reading list of target names
Const INPUT_FILE_NAME = "C:\users.txt"
Const FOR_READING = 1
'Opens file and reads all data in file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strNames = objFile.ReadAll
objFile.Close
'Separates file by carriage return/line feed
strNTName = Split(strNames, vbCrLf)
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use the NameTranslate object to find the NetBIOS domain name from
the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init 3, strDNSDomain
objTrans.Set 1, strDNSDomain
strNetBIOSDomain = objTrans.Get(3)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
For Each strName In strNTName
objTrans.Init 1, strNetBIOSDomain
objTrans.Set 3, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(1)
objTextFile.WriteLine "User DN: " & strUserDN
Next
objTextFile.Close
+++++++++++++++++++++++++
Any ideas?
Thanks.