How to export AD group members taking input from excel file

Mohd Arif 946 Reputation points
2022-03-23T09:16:43.42+00:00

I have an excel file where I have all the groups listed. I have been asked to export all the group members. There are almost 500 groups. So I want to take input from my excel file and then export all the members information. I need at least "Group Name" "DisplayName" "samaccount" ,

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,413 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,738 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,580 questions
0 comments No comments
{count} votes

Accepted answer
  1. SChalakov 10,396 Reputation points MVP
    2022-03-23T10:00:55.847+00:00

    Hi @Mohd Arif ,

    You can convert your Excel file to CSV, this is easly done:

    Convert Excel file (XLSX) to CSV in Powershell
    https://excel.officetuts.net/examples/convert-excel-file-xlsx-to-csv-in-powershell/

    Depending on how your CSV is exactly structured (in particular the headers) you need to do the following:

    $Groups = Import-CSV "Path top the CSV" -Header "Column1","Column2"  
    

    Here a reference regarding the import:

    Import-Csv
    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-7.2

    Afterwards you can loop over the groups and get their members:

    foreach ($Group in $Groups) {  
      
    Get-ADGroupMember -identity $Grooup | select DisplayName, name, samaccountname | Export-csv -path c:\filename.csv -Notypeinformation  
      
    }  
    

    You have to just see test it out, but the approach is prettyy straight forward.

    Hope I was able to help.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Stoyan Chalakov

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Mohd Arif 946 Reputation points
    2022-04-18T11:36:15.663+00:00

    I found my answer here in below link, just nice one for my task.

    https://superit.in/how-to-export-ad-group-members-with-powershell/

    1 person found this answer helpful.
    0 comments No comments

  2. Mohd Arif 946 Reputation points
    2022-03-23T10:08:50.507+00:00

    It is not working, below error

    Get-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    At line:5 char:30

    • Get-ADGroupMember -identity $Grooup | select DisplayName, name, sama ...
    • ~~~~~~~
    • CategoryInfo : InvalidData: (:) [Get-ADGroupMember], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMember

  3. Mohd Arif 946 Reputation points
    2022-03-23T10:37:16.753+00:00

    Out Put is not in correct format. I need output like "Group Name", "Username for example aktir, akdie" "Display Name for example, Atif Khan"
    ![185996-image.png]1

    0 comments No comments

  4. SChalakov 10,396 Reputation points MVP
    2022-03-23T10:48:53.803+00:00

    Hi @Mohd Arif ,

    what if the user is member of more than one group? Should he/she be listed twice in the export?

    Regards,
    Stoyan

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.