Login | |
|
 |
Extract Group Members to a Text File - 8/10/2005 12:50:26 AM
|
|
 |
|
| |
esnmb
Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
|
This script will search an OU for a specified Group Name based on Instr. Create text files and adds the user to them. On Error Resume Next Set objShell = Wscript.CreateObject("Wscript.Shell") objDesktop = objShell.SpecialFolders("Desktop") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOU = GetObject("LDAP://OU=IT,OU=Security Groups,DC=MyDomain,DC=com") For Each Group In objOU If InStr(Group.Name, "CN=TestGroupName") Then Set objFile = objFSO.CreateTextFile(objDesktop & "\" & Group.CN & ".txt", 2) objFile.WriteLine Group.CN objFile.WriteLine "=======================" objFile.WriteLine Set objGroup = GetObject _ ("LDAP://" & Group.Name & ",OU=IT,OU=Security Groups,DC=mlnusa,DC=com") objGroup.GetInfo arrMemberOf = objGroup.GetEx("member") For Each strMember In arrMemberOf Set objUser = GetObject("LDAP://" & strMember) objFile.WriteLine objUser.samaccountname Next objFile.Close End If Next MsgBox "Completed script.",64,"Informational"
|
|
| |
|
|
|
 |
RE: Extract Group Members to a Text File - 1/2/2007 7:12:53 PM
|
|
 |
|
| |
A.Bedeker
Posts: 8
Score: 0
Joined: 12/21/2006
Status: offline
|
I made some changes in the script to export only the members of a specified global group. Problem however is that after my changes I don't get txt files.. Could someone check my script? (I couldn't get it in a codebox...): On Error Resume Next gga= inputbox("Which global group?") Set objShell = Wscript.CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOU = GetObject("LDAP://OU=Application Management Group,OU=Security Groups,DC=AD,DC=Intra") 'input the full LDAP path to your group's OU here objDesktop = objShell.SpecialFolders("Desktop") For Each Group In objOU If InStr(Group.Name, gga) Then 'input the name of the AD group to query here Set objFile = objFSO.CreateTextFile(objDesktop & "\Output_" & Group.Name & ".txt", 2) objFile.WriteLine Group.Name objFile.WriteLine "=======================" objFile.WriteLine Set objGroup = GetObject _ ("LDAP://" & Group.Name & ",OU=Application Management Group,OU=Security Groups,DC=Ad,DC=Intra") 'input the full LDAP path to your group's OU here objGroup.GetInfo arrMemberOf = objGroup.GetEx("member") For Each strMember In arrMemberOf Set objUser = GetObject("LDAP://" & strMember) objFile.WriteLine objUser.samaccountname Next objFile.Close End If Next MsgBox "Completed script.",64,"Informational"
|
|
| |
|
|
|
 |
RE: Extract Group Members to a Text File - 1/3/2007 1:53:18 AM
|
|
 |
|
| |
Country73
Posts: 710
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
|
(I left the 'code' blocks out to use colored text to show what I added) I added an echo so that you will get a message if the specified group is found. (bold red line) Do you get a response when you run this? If you don't, then that is why you don't get any text files. '===code=== On Error Resume Next gga= inputbox("Which global group?") Set objShell = Wscript.CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOU = GetObject("LDAP://OU=Application Management Group,OU=Security Groups,DC=AD,DC=Intra") 'input the full LDAP path to your group's OU here objDesktop = objShell.SpecialFolders("Desktop") For Each Group In objOU If InStr(Group.Name, gga) Then 'input the name of the AD group to query here wscript.echo gga & " group found" Set objFile = objFSO.CreateTextFile(objDesktop & "\Output_" & Group.Name & ".txt", 2) objFile.WriteLine Group.Name objFile.WriteLine "=======================" objFile.WriteLine Set objGroup = GetObject("LDAP://" & Group.Name & ",OU=Application Management Group,OU=Security Groups,DC=Ad,DC=Intra") 'input the full LDAP path to your group's OU here objGroup.GetInfo arrMemberOf = objGroup.GetEx("member") For Each strMember In arrMemberOf Set objUser = GetObject("LDAP://" & strMember) objFile.WriteLine objUser.samaccountname Next objFile.Close End If Next MsgBox "Completed script.",64,"Informational" '===end code===
|
|
| |
|
|
|
 |
RE: Extract Group Members to a Text File - 1/3/2007 7:15:22 PM
|
|
 |
|
| |
A.Bedeker
Posts: 8
Score: 0
Joined: 12/21/2006
Status: offline
|
The script worked just fine... the globalgroup name was in capital....I had to enter the exact name.
|
|
| |
|
|
|
 |
RE: Extract Group Members to a Text File - 1/3/2007 9:12:29 PM
|
|
 |
|
| |
A.Bedeker
Posts: 8
Score: 0
Joined: 12/21/2006
Status: offline
|
Here is the final result: code: On Error Resume Next Dim UserCount, gga, CNgga gga= inputbox("Which global group?") 'Get the requested Global Group CNgga = "CN="&gga 'Change the group to a CN request Set objShell = Wscript.CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOU = GetObject("LDAP://OU=Application Management Groups,OU=Security Groups,DC=AD,DC=Intra") 'input the full LDAP path to your group's OU here objDesktop = objShell.SpecialFolders("Desktop") 'Folder for the output file For Each Group In objOU If InStr(Group.Name, CNgga) Then 'input the name of the AD group to query here Set objFile = objFSO.CreateTextFile(objDesktop & "\AD\Members of " & Group.Name & ".txt", 2) 'Create the file set UserCount = 0 objFile.WriteLine Group.Name objFile.WriteLine "==================================" Set objGroup = GetObject ("LDAP://" & Group.Name & ",OU=Application Management Groups,OU=Security Groups,DC=AD,DC=Intra") 'input the full LDAP path to your group's OU here objGroup.GetInfo arrMemberOf = objGroup.GetEx("member") For Each strMember In arrMemberOf Set objUser = GetObject("LDAP://" & strMember) Select Case objUser.class Case "user" objFile.WriteLine " " & objUser.samaccountname &" - " & objUser.Class UserCount = UserCount + 1 Case "group" 'objFile.WriteLine objUser.samaccountname &" - " & objUser.Class &" - " & objUser.distinguishedName enumGroupMembers(objUser.distinguishedName) End Select Next objFile.WriteLine "Aantal gebruikers: " & UserCount 'Gives a total count of all the users. objFile.Close End If Next MsgBox "Completed script.",64,"Informational" Sub enumGroupMembers(sObjDN) Dim oContainer, obj, sDN Set oContainer=GetObject ("LDAP://" & sObjDN) For each obj in oContainer.members Select Case LCase(obj.Class) Case "user" , "contact" objFile.WriteLine " " & obj.sAMAccountName &" - " & obj.Class UserCount = UserCount + 1 Case "group" 'objFile.WriteLine obj.sAMAccountName &" - " & obj.Class &" - " & objUser.distinguishedName EnumGroupMembers obj.distinguishedName End Select Next End Sub
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|