How to get the AD user group membership details at once RRS feed

  • Question

  • Hi,

    How do I get the user's AD group membership details & if possible then I wish to send them an email too.

    There is a PS command Get-ADPrincipalGroupMembership Username | Select Name 

    But it will be very tedious to manually run it for n.. of users.




    Friday, February 16, 2018 11:41 AM

All replies

  • A good place to start would be to learn PowerShell as this is a fairly simple task. Please note that this forum wont write a script for you, let us know what you have tried so far and what specific issues you are having.

    Start by learning the foreach command.

    Friday, February 16, 2018 11:48 AM
  • Hi,

    Do you need a script that loops throu an OU and writes/mails the users in the OU their membership?


    Friday, February 16, 2018 11:53 AM
  • Get-AdUser -Filter * | Get-ADPrincipalGroupMembership | Select Name

    Please take the time to learn PowerShell.   Your question is answered in one of the very first chapters of most tutorials.

    If you want pre-written scripts look in the Gallery.  For script requests use the link below:

    Please carefully review the following links to set your expectation of technical forums.

    This Forum is for Scripting Question Rather than script requests

    Script Gallery.

    Learn PowerShell  

    Script requests

    Learn PS now before it is too late.


    Friday, February 16, 2018 12:09 PM
  • Import-Module ActiveDirectory
    $users = Get-ADUser -SearchBase "OU=Users,OU=whatever,DC=domain,DC=local" -Filter * 
    $logfile = "C:\output.txt"
    foreach($user in $users){
      add-content $logfile $user.Name
      $groups = Get-ADPrincipalGroupMembership $user.SamAccountName 
      foreach($group in $groups){
        add-content $logfile $group.name
    to start :-)
    Friday, February 16, 2018 12:19 PM
  • You don't need to import the Active Directory module. It will do this automatically.
    Friday, February 16, 2018 1:35 PM
  • Thanks all for your time to reply.

    guess few ppl have misunderstood - I have NOT asked someone to write a script for me.

    suggestions are welcome.



    Tuesday, February 27, 2018 10:20 AM
  • Hi Atul,

    I'm checking how the issue is going, was your issue resolved?

    And if the replies as above are helpful, we would appreciate you to mark them as answers, and if you resolve it using your own solution, please share your experience and solution here. It will be greatly helpful to others who have the same question.

    Appreciate for your feedback.

    Best Regards,

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, February 28, 2018 1:52 AM