Export AD Group members

Glenn Maxwell 6,556 Reputation points
2020-10-05T10:35:17.5+00:00

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.
3,665 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.
2,913 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,097 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.
4,630 questions
No comments
{count} votes

Accepted answer
  1. Eric Yin-MSFT 4,441 Reputation points
    2020-10-06T02:43:57.297+00:00
    1. For command Get-ADGroupMember, identity has to be the highlight values:
      30305-1.png
      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:
      30294-2.png

    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. Anonymous
    2020-10-05T11:07:28.537+00:00

    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))}}  
    

    Regards,
    Stoyan

    No comments

  2. Rich Matheisen 35,266 Reputation points
    2020-10-05T19:01:20.227+00:00

    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.

    No comments