I want to add ObjUser.DisplayName to my script

I want to add ObjUser.DisplayName as an output to my script on line 31 or 32 but it is not working. Why not and what can I do to make it work?
Thanks.
Dim aServerName(150)
Dim aServerIP(150)
 
Set objNetwork = CreateObject("Wscript.Network")
'strComputer = objNetwork.ComputerName
'strComputer="2.1.1.10"
'strComputer="Domain11"
 
aServerName(0)="Example.ex.com"
aServerIP(0)="1.1.1.1"
 
fileName ="Example.txt"
 
OutputFile = "c:\myscripts\script io\automated tasks\atm network settlement\" & fileName
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Wshshell = Wscript.CreateObject("Wscript.Shell")
Set Output = Fso.OpentextFile(OutputFile, 2, True)
 
output.writeline "Server Name, IP Address, Group Name, Username, Class"
 
x=0
For each strcomputer in AServerIP
 
      If strComputer = "" then Exit For end if
 
      Set colAccounts = GetObject("WinNT://" & strcomputer & "")
      colAccounts.Filter = Array("group")
 
      For Each objgroup In colAccounts
          for each objUser in objGroup.Members
            output.writeline aServerName(x) & "," & strComputer & "," & ObjGroup.Name & "," & objUser.Name _
											& "," & ObjUser.Class
          next
      Next
     x=x+1
Next
wscript.echo "Script Completed"

Open in new window

reason4xistenceAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yehudahaCommented:
hey

i added a function name :  FindDisplayName.so  your script can display AD display name to the users

just use it and the location you want

example

 this line:

 output.writeline aServerName(x) & "," & strComputer & "," & ObjGroup.Name & "," & objUser.Name _
                                                                                        & "," & ObjUser.Class

can be:

 output.writeline aServerName(x) & "," & strComputer & "," & ObjGroup.Name & "," & objUser.Name _
 & "," & ObjUser.Class & "," & FindDisplayName(objUser.Name)

you put in the brackets () the user name
Dim aServerName(150)
Dim aServerIP(150)
 
Set objNetwork = CreateObject("wscript.network")
strDomain = "LDAP://" & objNetwork.UserDomain
 
'strComputer = objNetwork.ComputerName
'strComputer="2.1.1.10"
'strComputer="Domain11"
 
aServerName(0)="Example.ex.com"
aServerIP(0)="1.1.1.1"
 
fileName ="Example.txt"
 
OutputFile = "c:\myscripts\script io\automated tasks\atm network settlement\" & fileName
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Wshshell = Wscript.CreateObject("Wscript.Shell")
Set Output = Fso.OpentextFile(OutputFile, 2, True)
 
output.writeline "Server Name, IP Address, Group Name, Username, Class"
 
x=0
For each strcomputer in AServerIP
 
      If strComputer = "" then Exit For end if
 
      Set colAccounts = GetObject("WinNT://" & strcomputer & "")
      colAccounts.Filter = Array("group")
 
      For Each objgroup In colAccounts
          for each objUser in objGroup.Members
            output.writeline aServerName(x) & "," & strComputer & "," & ObjGroup.Name & "," & objUser.Name _
                                                                                        & "," & ObjUser.Class
          next
      Next
     x=x+1
Next
wscript.echo "Script Completed"
 
Function FindDisplayName(User)
                                                
        selectedProperties = "Displayname"
                                                
        Set oCn = CreateObject("ADODB.Connection")
        Set oCmd = CreateObject("ADODB.Command")
        oCn.Provider = "ADsDSOObject"
        oCn.Open "Active Directory Provider"
        Set oCmd.ActiveConnection = oCn
        oCmd.Properties("Page Size") = 1000
        oCmd.Properties("Searchscope") = 2 
        oCmd.CommandText = "SELECT " & selectedProperties & " FROM '" & strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & User & "'"
                                                
        Set oRS = oCmd.Execute
        Do Until oRS.EOF
                FindDisplayName = oRS.Fields(selectedProperties).Value
                oRS.MoveNext
        Loop
End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yehudahaCommented:
did it for you
Dim aServerName(150)
Dim aServerIP(150)
 
Set objNetwork = CreateObject("wscript.network")
strDomain = "LDAP://" & objNetwork.UserDomain
 
'strComputer = objNetwork.ComputerName
'strComputer="2.1.1.10"
'strComputer="Domain11"
 
aServerName(0)="Example.ex.com"
aServerIP(0)="1.1.1.1"
 
fileName ="Example.txt"
 
OutputFile = "c:\myscripts\script io\automated tasks\atm network settlement\" & fileName
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Wshshell = Wscript.CreateObject("Wscript.Shell")
Set Output = Fso.OpentextFile(OutputFile, 2, True)
 
output.writeline "Server Name, IP Address, Group Name, Username, Class, Display Name"
 
x=0
For each strcomputer in AServerIP
 
      If strComputer = "" then Exit For end if
 
      Set colAccounts = GetObject("WinNT://" & strcomputer & "")
      colAccounts.Filter = Array("group")
 
      For Each objgroup In colAccounts
          for each objUser in objGroup.Members
            output.writeline aServerName(x) & "," & strComputer & "," & ObjGroup.Name & "," & objUser.Name _
 & "," & ObjUser.Class & "," & FindDisplayName(objUser.Name)
 
          next
      Next
     x=x+1
Next
wscript.echo "Script Completed"
 
Function FindDisplayName(User)
                                                
        selectedProperties = "Displayname"
                                                
        Set oCn = CreateObject("ADODB.Connection")
        Set oCmd = CreateObject("ADODB.Command")
        oCn.Provider = "ADsDSOObject"
        oCn.Open "Active Directory Provider"
        Set oCmd.ActiveConnection = oCn
        oCmd.Properties("Page Size") = 1000
        oCmd.Properties("Searchscope") = 2 
        oCmd.CommandText = "SELECT " & selectedProperties & " FROM '" & strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & User & "'"
                                                
        Set oRS = oCmd.Execute
        Do Until oRS.EOF
                FindDisplayName = oRS.Fields(selectedProperties).Value
                oRS.MoveNext
        Loop
End Function

Open in new window

reason4xistenceAuthor Commented:
That works. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.