Share via


How to get the AD user group membership details at once

Question

Friday, February 16, 2018 11:41 AM

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.

-Atul

 

TheAtulA

All replies (7)

Friday, February 16, 2018 11:48 AM

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:53 AM

Hi,

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

Iwan


Friday, February 16, 2018 12:09 PM | 1 vote

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:19 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 1:35 PM

You don't need to import the Active Directory module. It will do this automatically.


Tuesday, February 27, 2018 10:20 AM

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.

-Atul

TheAtulA


Wednesday, February 28, 2018 1:52 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,
Albert

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]