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 for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. SChalakov 10,576 Reputation points MVP Volunteer Moderator
    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. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  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,576 Reputation points MVP Volunteer Moderator
    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.