Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I want to add ObjUser.DisplayName to my script

Posted on 2009-02-23
3
Medium Priority
?
1,634 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:reason4xistence
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
yehudaha earned 2000 total points
ID: 23716180
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
 
LVL 14

Expert Comment

by:yehudaha
ID: 23716242
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
 

Author Closing Comment

by:reason4xistence
ID: 31550312
That works. Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question