Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Active Directory
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Export Global Group Members samacountname(s) to Text File

Active Directory


Reply
 
Thread Tools Search this Thread
  #1  
Old 14-11-2009
Stuscotland
 
Posts: n/a
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
Reply With Quote
  #2  
Old 14-11-2009
Richard Mueller [MVP]
 
Posts: n/a
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
--


Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Active Directory


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 10:06 PM.