|
| |||||||||
| Tags: export, global, group, members, samacountnames, text |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Export Global Group Members samacountname(s) to Text File
Hi I need to take the members of a global group and export their samaccountnames. I'm sure this isn't a huge task. Can someone advise on the least painless way to do this - i am in the middle of a 3000 user migration and need a quick fix! Cheers |
|
#2
| |||
| |||
| Re: Export Global Group Members samacountname(s) to Text File "Stuscotland" <Stuscotland@discussions.microsoft.com> wrote in message news:38950585-04CF-4551-B39B-5E5BCE6AC15F@microsoft.com... > Hi > I need to take the members of a global group and export their > samaccountnames. I'm sure this isn't a huge task. Can someone advise on > the > least painless way to do this - i am in the middle of a 3000 user > migration > and need a quick fix! > > Cheers You can use dsget, but only if all members are users (no groups or computers): dsget group "cn=My Group,ou=West,dc=MyDomain,dc=com" -members | dsget user -samid Otherwise, a VBScript program can show sAMAccountName of all members of a group: ========== ' Bind to group with Distinguished Name. Set objGroup = GetObject("LDAP://cn=My Group,ou=West,dc=MyDomain,dc=com") ' Enumerate all direct members. For Each objMember In objGroup.Members Wscript.Echo objMember.sAMAccountName Next ========= However, if the group is large, this will be slow as it must bind to each member object. A faster solution (but with more code) uses ADO. For example: ============== Option Explicit Dim adoCommand, adoConnection, strBase, strFilter, strAttributes Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName ' Setup ADO objects. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection ' Search entire Active Directory domain. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") strBase = "<LDAP://" & strDNSDomain & ">" ' Filter on direct members of group. strFilter = "(memberOf=cn=My Group,ou=West,dc=MyDomain,dc=com)" ' Comma delimited list of attribute values to retrieve. strAttributes = "sAMAccountName" ' Construct the LDAP syntax query. strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" adoCommand.CommandText = strQuery adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False ' Run the query. Set adoRecordset = adoCommand.Execute ' Enumerate the resulting recordset. Do Until adoRecordset.EOF ' Retrieve values. strName = adoRecordset.Fields("sAMAccountName").Value Wscript.Echo strName ' Move to the next record in the recordset. adoRecordset.MoveNext Loop ' Clean up. adoRecordset.Close adoConnection.Close ========== To restrict output to user objects (no groups or computers), change the filter to: strFilter = "(&(objectCategory=person)(objectClass=user)" _ & "(memberOf=cn=My Group,ou=West,dc=MyDomain,dc=com))" Finally, if the group is Domain Users, then I would expect all users to have this group designated as their "primary" group. None of the methods above will reveal membership in this group. Instead, you must use ADO to retrieve all users where the value of the primaryGroupID attribute is 513. For this you can use the code I posted above, but use the filter: strFilter = "(primaryGroupID = 513)" -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Export Global Group Members samacountname(s) to Text File" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Listing members of Group with >1500 members | Umesh Thakur | Windows Server Help | 11 | 1 Week Ago 05:29 AM |
| Display members of a group with more than 1500 members | Simon G | Windows Server Help | 5 | 25-10-2011 01:35 PM |
| Security Group - Global Problem - Not showing members | TimParker | Active Directory | 8 | 13-05-2009 04:50 AM |
| Export Group Members | seankil | Windows Server Help | 4 | 09-04-2008 10:05 PM |
| How to export list of users from each global, domain, local group? | Mugen | Active Directory | 1 | 10-06-2005 08:52 AM |