Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Active Directory > Export Global Group Members samacountname(s) to Text File

Reply
Thread Tools Display Modes

Export Global Group Members samacountname(s) to Text File

 
 
Stuscotland
Guest
Posts: n/a

 
      11-13-2009
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
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      11-13-2009

"Stuscotland" <> wrote in message
news:38950585-04CF-4551-B39B-...
> 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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Media Player (11) is not installed properly. Reinstall... Godenjoyer Windows Media Player 19 10-28-2009 11:50 PM
Push a HOSTS file via Group Policy Jeff Active Directory 5 10-21-2009 06:35 PM
blobl text file dysonsphere Windows Vista Performance 1 05-14-2007 03:15 PM
HELP sfc /scannow William Beard Windows Vista Performance 17 05-11-2007 04:28 AM
cloning laptop sata harddrive vista premium Mark Ryan Windows Vista Hardware 5 04-26-2007 07:44 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59