Hello Spice Team,<\/p>\n
I am trying to get all the AD group memberships that a list of users. Here is the code that I have created so far. The only problem is I can see is that I get Membership names but not whos that membership belongs too.<\/p>\n
$names = \"jsmith\", \"ajohnson\"\n\nforEach($names in $names)\n{\n Get-adprincipalgroupmembership -Identity $names | select name, samaccountname\n\n}\n<\/code><\/pre>","upvoteCount":2,"answerCount":7,"datePublished":"2020-05-18T17:13:40.000Z","author":{"@type":"Person","name":"spiceking","url":"https://community.spiceworks.com/u/spiceking"},"acceptedAnswer":{"@type":"Answer","text":"
Advertisement
or if you want it a bit cleaner like so<\/p>\n
$names = \"jsmith\", \"ajohnson\"\n$Report = \nforEach ($name in $names){\n $membership = Get-adprincipalgroupmembership -Identity $name | select name, samaccountname\n foreach ($grp in $membership) {\n [pscustomobject]@{\n UserName = $name\n GroupName = $grp.name\n GroupSamAccountname = $grp.samaccountname\n }\n }\n}\n$report \n$report | export-csv \".\\GroupMembershipReport.csv\" -NoTypInformation\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2020-05-18T17:23:40.000Z","url":"https://community.spiceworks.com/t/powershell-get-adprincipalgroupmembership/763071/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"Hello Spice Team,<\/p>\n
I am trying to get all the AD group memberships that a list of users. Here is the code that I have created so far. The only problem is I can see is that I get Membership names but not whos that membership belongs too.<\/p>\n
$names = \"jsmith\", \"ajohnson\"\n\nforEach($names in $names)\n{\n Get-adprincipalgroupmembership -Identity $names | select name, samaccountname\n\n}\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2020-05-18T17:13:40.000Z","url":"https://community.spiceworks.com/t/powershell-get-adprincipalgroupmembership/763071/1","author":{"@type":"Person","name":"spiceking","url":"https://community.spiceworks.com/u/spiceking"}},{"@type":"Answer","text":"Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n