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.

Re: Convert SAM to DN with input/output files by Michael

Michael
Fri Oct 07 22:27:09 CDT 2005

There is a couple of things I notice right off the bat.
strNTName is an array that is made when you use the split command.
Using a str prefix is misleading. Consider renaming it arrNTName

I'm guessing that the line that is failing is this one.
objTrans.Set 3, strNetBIOSDomain & "\" & strNTName

Try changing the strNTName to strName which is the actual item in the
array based upon your "For" loop.

Michael Reese
Information Systems Technician


Re: Convert SAM to DN with input/output files by DJP

DJP
Sat Oct 08 18:13:52 CDT 2005

Also, how are you declaring your array? If it is "Dim strNTName()", try
changing it to "Dim arrNTName" (ie. remove the parenthesis).


"Michael Reese" <mnreese@hotmail.com> wrote in message
news:1128742029.705529.11300@f14g2000cwb.googlegroups.com...
> There is a couple of things I notice right off the bat.
> strNTName is an array that is made when you use the split command.
> Using a str prefix is misleading. Consider renaming it arrNTName
>
> I'm guessing that the line that is failing is this one.
> objTrans.Set 3, strNetBIOSDomain & "\" & strNTName
>
> Try changing the strNTName to strName which is the actual item in the
> array based upon your "For" loop.
>
> Michael Reese
> Information Systems Technician
>



Re: Convert SAM to DN with input/output files by User

User
Mon Oct 10 10:28:32 CDT 2005

Michael-

Thanks. I was using some code from one of my other scripts and hadn't
updated it yet. I've updated strNTName to arrNTName for better
clarity.

Thereafter, I updated the failing line with the correct item as you
pointed out.

Script is now working perfectly.

Appreciate the help.



On 7 Oct 2005 20:27:09 -0700, "Michael Reese" <mnreese@hotmail.com>
wrote:

>There is a couple of things I notice right off the bat.
>strNTName is an array that is made when you use the split command.
>Using a str prefix is misleading. Consider renaming it arrNTName
>
>I'm guessing that the line that is failing is this one.
> objTrans.Set 3, strNetBIOSDomain & "\" & strNTName
>
>Try changing the strNTName to strName which is the actual item in the
>array based upon your "For" loop.
>
>Michael Reese
>Information Systems Technician


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----