Export AD Group members

Glenn Maxwell 8,796 Reputation points

Hi Experts
i have a AD Security group and mail enabled security group, i want to export their members. when i use the below syntax i am getting output.

Get-ADGroupMember -identity "group@Company portal .com" | select name | Export-csv -path C:\output.csv -NoTypeInformation

When i am trying the below syntax i am not getting output. i want to use this to export AD group members, mail enabled security group members and distribution group members. please correct me with the syntax.

Get-ADGroupMember -identity "group@Company portal .com" -Properties DisplayName,Userprincipalname,title,Office,description,co,personalTitle,DepartmentNumber,employeeNumber | Select DisplayName,Userprincipalname,title,Office,employeeNumber,description,co,personalTitle,@{Name='DepartmentNumber';Expression={[string]::join(";", $($_.DepartmentNumber))}} | Export-csv C:\output.csv -Notypeinformation

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,141 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
3,855 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
6,995 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,167 questions
0 comments No comments
{count} votes

Accepted answer
  1. Eric Yin-MSFT 4,456 Reputation points
    1. For command Get-ADGroupMember, identity has to be the highlight values:
      So group@Company portal .com will not work.
    2. As RichMatheisen says, Get-ADGroupMember cannot read those property you want.
    3. For aduser property, there's no "co", I assume you want "company", correct it to any value as you want:

    Please inform me if there's any error:

    (Get-ADGroupMember -identity "sg3-11664937739").name |  
      get-aduser -properties DisplayName,Userprincipalname,title,Office,description,company,personalTitle,DepartmentNumber,employeeNumber|  
      Select DisplayName,Userprincipalname,title,Office,employeeNumber,description,company,personalTitle,@{N='Departmentnumber';E={$_.Departmentnumber[0]}}|  
      Export-csv C:\temp\output.csv -Notypeinformation  

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

2 additional answers

Sort by: Most helpful
  1. SChalakov 10,151 Reputation points MVP

    Hi @Glenn Maxwell ,

    can you do a simple test and try without the expression, you have defined:

    Get-ADGroupMember -identity "group@contoso.com" -Properties DisplayName,Userprincipalname,title,Office,description,co,personalTitle,DepartmentNumber,employeeNumber | Select DisplayName,Userprincipalname,title,Office,employeeNumber,description,co,personalTitle | Export-csv C:\output.csv -Notypeinformation  

    Do you get a result? If Yes, then you need to check just the expression:

    @{Name='DepartmentNumber';Expression={[string]::join(";", $($_.DepartmentNumber))}}  


    0 comments No comments

  2. Rich Matheisen 42,826 Reputation points

    Get-ADGroupMember does not retrieve the user object from the AD. It simply returns the identity of each member. You have to use the member's identity by piping the output of Get-ADGroupMember into Get-ADUser and then pipe the output from that into your Select-Object.

    0 comments No comments