I am relatively new to powershell and I have two statements on the cmd line:
get-adgroupmember <group name> | select-object name,samaccountname
To produce a nicely formatted table with two columns of a persons real name and their username.
get-adgroupmember <group name> | get-adprincipalgroupmembership | select-object name
To produce list of groups that each user in a named group belongs to.
I would like to combine these so that I have a users real name + username and then the groups they belong to for each user e.g.
name samaccountname memberof ---- -------------- -------- joe bloggs jbloggs group1 group2 groupq bob laithwaite blaithwaite group2 groupm groupp groupq
joe bloggs jbloggs group1 group2 groupq bob laithwaite blaithwaite group2 groupm groupp groupq
Is there any simple way to create this? I am not overly concerned about it being beautiful.
If there is no simple way can anyone give me any pointers to how I can create this a difficult way? If there is only a difficult way then whilst a working answer would be nice I would sooner have pointers to start with to see if I can produce something myself. I am still learning after all.
My original Google search found https://gallery.technet.microsoft.com/scriptcenter/Powershell-Get-users-who-b0420fe1 but could not get it to work on the cmd line by replacing variables with hard coded strings. This is what I ultimately want to achieve but with just 2 groups however in the first instance I want to start with something like the output above.
I also found How can I generate a list of the security groups a set of users belong to? in the process of writing this question but this just appears to produce similar list to that which I created in the 2nd cmd line, the one that uses get-adprincipalgroupmembership.