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?
 
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

0
 
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

0
 
reason4xistenceAuthor Commented:
That works. Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.