Issue:
I need a list of all of the user groups from a system and what users are inside of them.
Now I notice that there are not just users, there are users both local and domain, and also possible other groups. The domain part is interesting. Also the groups in a group poses a problem. It doesn't give me the user.
Now I notice that there are not just users, there are users both local and domain, and also possible other groups. The domain part is interesting. Also the groups in a group poses a problem. It doesn't give me the user.
Problems?
Well of course there were problems.
a. The servers i needed to talk to are locked down tighter than Uncle Scrooges coin purse. So no getting the information remotely.
The resolution 1:
Make a script to export this information. I ultimately ended up using VBScript as i usually end up doing for these types of scripts. After some googling and stitching together of some code I ended up with this. It is a script that dumps a tab delimited text file to your desktop of all the groups with their users/groups listed.
The Code 1:
'Set the var objShell to run shell commands against
Set objShell = CreateObject("WScript.Shell")
'Set the var userProfilePath using previous shell variable to get the users profile path
userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")
'Set the var wshNetwork to equal the network object
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
'Set the var strComputerName as the computers name using the previous network object var
strComputerName = wshNetwork.ComputerName
'Set where to dump th txt file too.
outFile = userProfilePath & "\desktop\output1.txt"
'Create the file the "true" flag is there to overwrite the file if it exists.
Set objFile = objFSO.CreateTextFile(outFile,True)
'Create variables to be used later
Dim host
Dim group
Dim member
'Set the host, computer name, to be used to look up the. Since i do not have network access I just use localhost.
host = "localhost"
'Loop through the results of GetObject to get all the "groups"
For Each group In GetObject("WinNT://" & host)
'Self-explanatory
If group.Class = "Group" Then
'Loop through the members of that group to get a list of the members
For Each member In group.members
'write the computer name, group and its members to the txt file.
objFile.Write strComputerName & vbTab & group.name & vbTab & member.name & vbCrLf
'Go to the next member till no more members in that group
Next
'End the if statement if the group class is not a group class type.
End If
'End the loop of all the class objects.
Next
Set objShell = CreateObject("WScript.Shell")
'Set the var userProfilePath using previous shell variable to get the users profile path
userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")
'Set the var wshNetwork to equal the network object
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
'Set the var strComputerName as the computers name using the previous network object var
strComputerName = wshNetwork.ComputerName
'Set where to dump th txt file too.
outFile = userProfilePath & "\desktop\output1.txt"
'Create the file the "true" flag is there to overwrite the file if it exists.
Set objFile = objFSO.CreateTextFile(outFile,True)
'Create variables to be used later
Dim host
Dim group
Dim member
'Set the host, computer name, to be used to look up the. Since i do not have network access I just use localhost.
host = "localhost"
'Loop through the results of GetObject to get all the "groups"
For Each group In GetObject("WinNT://" & host)
'Self-explanatory
If group.Class = "Group" Then
'Loop through the members of that group to get a list of the members
For Each member In group.members
'write the computer name, group and its members to the txt file.
objFile.Write strComputerName & vbTab & group.name & vbTab & member.name & vbCrLf
'Go to the next member till no more members in that group
Next
'End the if statement if the group class is not a group class type.
End If
'End the loop of all the class objects.
Next
Used http://www.moretechtips.net/2008/11/how-to-code-beautifier-and-formatter.html for the code formatting.
Problems #2?
I need the FULL list of users. Lets see if we can get a list of users from the groups of the groups we just pulled from.. umm.. could this turn into an infinite loop?
Info finding:
So after the "For Each member In group.members" i did some digging after finding some other properties i could dig into.I am using WScript.Echo member.? to get the information.. so like WScript.Echo member.class
class = the class of the object, such as; user and group
AdsPath = gives the path of the object..
Formatted like: WinNT://pathName/objectName
Example: WinNT://MyComputer21/Bob
Name = the name of the object.. like the name: Bob
Parent = This one gives where the object comes from.. this i want..
Formated like WinNT://location
Example: Domain = WinNT://MICROSOFT
Machine = WinNT://MyComputer21
Parent = This one gives where the object comes from.. this i want..
Formated like WinNT://location
Example: Domain = WinNT://MICROSOFT
Machine = WinNT://MyComputer21
No comments:
Post a Comment