SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / server / Questions / 49405
Accepted
Flyer
Flyer
Asked: 2009-08-04 09:19:43 +0800 CST2009-08-04 09:19:43 +0800 CST 2009-08-04 09:19:43 +0800 CST

Command line to list users in a Windows Active Directory group?

  • 772

Is there a command line way to list all the users in a particular Active Directory group?

I can see who is in the group by going to Manage Computer --> Local User / Groups --> Groups and double clicking the group.

I just need a command line way to retrieve the data, so I can do some other automated tasks.

windows active-directory
  • 9 9 Answers
  • 1201442 Views

9 Answers

  • Voted
  1. asdasddfg
    2010-01-05T12:11:26+08:002010-01-05T12:11:26+08:00

    Here's another way from the command prompt, not sure how automatable though since you would have to parse the output:

    If group is "global security group":

    net group <your_groupname> /domain
    

    If you are looking for "domain local security group":

    net localgroup <your_groupname> /domain
    
    • 287
  2. Ryan Fisher
    2009-08-04T11:09:55+08:002009-08-04T11:09:55+08:00

    Here's a version of the ds command I found more typically useful, especially if you have a complex OU structure and don't necessarily know the full distinguished name of the group.

    dsquery group -samid "Group_SAM_Account_Name" | dsget group -members -expand
    

    or if you know the CN of the group, usually the same as the SAM ID, quoted in case there are spaces in the name:

    dsquery group -name "Group Account Name" | dsget group -members -expand
    

    As stated in the comments, by default the ds* commands (dsquery, dsget, dsadd, dsrm) are only available on a Domain Controller. However, you can install the Admin Tools pack from the Support Tools on the Windows Server installation media or download it from the Microsoft Download site.

    You can also perform these queries using PowerShell. PowerShell is already available as an installable feature for Server 2008, 2008 R2, and Windows 7, but you'll need to download the WinRM Framework to install it on XP or Vista.

    To get access to any AD-specific cmdlets in PowerShell you will ALSO need to perform at least one of the following installs:

    • For Win 7 and 2008 R2 clients, you can install the Remote Server Admin Tools. The RSAT also requires that you have installed the Active Directory Web Services feature on your Server 2008 R2 Domain Controllers, or the Active Directory Management Gateway Service for any Server 2003/2008 DCs.
    • For any XP or higher client, download and install the Quest ActiveRoles Management Shell for Active Directory. The Quest tools do not require any additional changes to your DCs.
    • 50
  3. Best Answer
    pQd
    2009-08-04T09:22:48+08:002009-08-04T09:22:48+08:00

    try

    dsget group "CN=GroupName,DC=domain,DC=name,DC=com" -members
    
    • 39
  4. pk.
    2011-03-25T08:41:04+08:002011-03-25T08:41:04+08:00

    For a PowerShell solution that doesn't require the Quest AD add-in, try the following

    Import-Module ActiveDirectory
    
    Get-ADGroupMember "Domain Admins" -recursive | Select-Object name
    

    This will enumerate the nested groups as well. If you don't wish to do so, remove the -recursive switch.

    • 29
  5. deajan
    2012-10-09T01:37:33+08:002012-10-09T01:37:33+08:00

    A very easy way which works on servers and clients:

    NET GROUP "YOURGROUPNAME" /DOMAIN | find /I /C "%USERNAME%"
    

    Returns 1 if user is in group YOURGROUPNAME, else will return 0

    You can then use the %ERRORLEVEL% value (0 if user in group, 1 if not) like

    IF %ERRORLEVEL%==0 NET USE %LOGONSERVER%\YOURGROUPSHARE
    
    • 18
  6. Gordon Bell
    2009-08-04T12:51:34+08:002009-08-04T12:51:34+08:00

    Using PowerShell and Quest Software's Free ActiveRoles Management Shell for Active Directory, you can use:

    (Get-QADGroup "GroupName").Members

    http://www.quest.com/powershell/activeroles-server.aspx

    • 10
  7. markshep
    2011-04-01T02:34:57+08:002011-04-01T02:34:57+08:00

    The answers here using dsget and dsquery will only work on server versions of Windows as those command's aren't shipped on other versions of Windows (e.g. Windows 7). On machines without those commands you can get the information you want using the AdFind command.

    Here's an example query for getting group membership:

    AdFind.exe -default -f name="Domain Admins" member -list
    
    • 8
  8. vadim
    2012-10-10T16:54:54+08:002012-10-10T16:54:54+08:00

    For display members of the UserGroup1 try:

    dsquery group -name UserGroup1 | dsget group -members | dsget user -display
    
    • 4
  9. Sysadmin
    2015-01-15T11:12:12+08:002015-01-15T11:12:12+08:00

    How to list local groups and users?

    Use the following powershell script to list the local groups and members of those groups.

    $server="YourServerName"
    $computer = [ADSI]"WinNT://$server,computer"
    
    $computer.psbase.children | where { 
    
    $_.psbase.schemaClassName -eq 'group' } | foreach {
        write-host $_.name
        write-host "------"
        $group =[ADSI]$_.psbase.Path
        $group.psbase.Invoke("Members") | foreach {
    $_.GetType().InvokeMember("Name", 'GetProperty', 
    
    $null, $_, $null)}
        write-host
    }
    

    Copy the text above in to notepad and save as filename.ps1. Then run the file. I should display the Groups and Users in each group, or you can just run this from powershell.

    • 4

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    Ping a Specific Port

    • 18 Answers
  • Marko Smith

    What port does SFTP use?

    • 6 Answers
  • Marko Smith

    Resolve host name from IP address

    • 8 Answers
  • Marko Smith

    How can I sort du -h output by size

    • 30 Answers
  • Marko Smith

    Command line to list users in a Windows Active Directory group?

    • 9 Answers
  • Marko Smith

    What's the command-line utility in Windows to do a reverse DNS look-up?

    • 14 Answers
  • Marko Smith

    How to check if a port is blocked on a Windows machine?

    • 4 Answers
  • Marko Smith

    What port should I open to allow remote desktop?

    • 9 Answers
  • Marko Smith

    What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats?

    • 3 Answers
  • Marko Smith

    How to determine if a bash variable is empty?

    • 15 Answers
  • Martin Hope
    Davie Ping a Specific Port 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    Deepak Mittal How to run a server on port 80 as a normal user on Linux? 2008-11-11 06:31:11 +0800 CST
  • Martin Hope
    MikeN In Nginx, how can I rewrite all http requests to https while maintaining sub-domain? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner How can I sort du -h output by size 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 What is the difference between double and single square brackets in bash? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch How do I change my private key passphrase? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt How does IPv4 Subnetting Work? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent How to determine if a bash variable is empty? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus How do you find what process is holding a file open in Windows? 2009-05-01 16:47:16 +0800 CST

Related Questions

Trending Tags

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve