Get-ADGroupMember syntax

Rising Flight 4,016 Reputation points
2021-09-06T19:32:54.03+00:00

Hi All

i have an AD security group and it has 500 security groups and 50 users added to it. if i use the below syntax will i be able to export the 500 AD groups and 50 members. i dont want to export users of 500 AD groups just the 500 AD groups and 50 users in it to a csv file.

Get-ADGroupMember -identity "ADGroup" | Select-Object Name,Description,UserprincipalName,SamAccountName| export-csv C:\temp\output.csv -NoTypeInformation
Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,547 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,418 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,558 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,435 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,181 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,431 Reputation points
    2021-09-06T21:13:21.91+00:00

    Provided "ADGroup" is an acceptable value to be used as an identity, yes. If you were to add the "-Recurse" switch you'd get the membership if "ADGroup" and the membership of all the groups that are a member of "ADGroup" and all the members of any groups that are members of those groups.

    Acceptable identity values are:

    A distinguished name  
    A GUID (objectGUID)  
    A security identifier (objectSid)  
    A Security Account Manager account name (sAMAccountName)  
    

    Note that the name of the group won't work.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,471 Reputation points
    2021-09-07T09:53:10.12+00:00

    Hello RisingFlight,

    It is not very clear what you are trying to achieve. You have one AD group with 500 security groups, and 50 users added to the main group?

    I would use Get-ADGroup -filter * | sort name | select name - to find the group name
    Then check if the list of users is the correct: Get-ADGroupMember -identity "yourADgroup"
    Then extract the membership of that group: Get-ADGroupMember -identity "yourADgroup" | select name | Export-csv -path c:\it\filename.csv -Notypeinformation (this will isolate member information for the group)

    About the groups within the group isolatedly: I would use the Get-NestedGroup

    Get-NestedGroup "yourADgroup" | Format-Table | | Export-csv -path c:\it\filename.csv -Notypeinformation

    Hope this is what you are looking for,

    Best regards,

    0 comments No comments