Hi everyone;<\/p>\n
I need your help for a request in powershell.<\/p>\n
I have a list of a few AD Groups, and i need for each group, to retrieve the members.<\/p>\n
The result i get from the cmd i used is not the the one i was expecting. It just displays all the users in those groups, without specifying which user is member of which group.<\/p>\n
Please can you tell me what is missing in my command ?<\/p>\n
$groups = Get-ADGroup -Filter * -searchBase ‘OU=SRV,OU=Accounts,DC=test,DC=NET’ -Properties name,description | where {$_.name -like ‘buil*’} | select name<\/p>\n
$ADgroupmember = $groups | ForEach-Object {Get-ADGroupMember $_.name} | select samaccountname<\/p>\n
$ADgroupmember | ForEach-Object {Get-ADUser $_.samaccountname | select name }<\/p>\n
Here is the result:<\/p>\n
Name<\/p>\n
John
\nfreddy_t2
\nGandalf_t2
\nMarvin
\nLinda
\nJohn
\nLinda_t2
\nMarvin
\nJohn
\nLinda_t2
\nfreddy_t2<\/p>\n
Big thanks in advance for your precious help.<\/p>","upvoteCount":11,"answerCount":7,"datePublished":"2023-02-26T11:57:36.000Z","author":{"@type":"Person","name":"tkam44","url":"https://community.spiceworks.com/u/tkam44"},"acceptedAnswer":{"@type":"Answer","text":"
Here’s one way to do it.<\/p>\n
$groups = Get-ADGroup -Filter * -searchBase 'OU=SRV,OU=Accounts,DC=test,DC=NET' -Properties name,description | where {$_.name -like 'buil*'} | select name\n\nforeach($group in $groups){Get-ADGroupMember $group.name | select @{name='groupname'; expression={$group.name}},samaccountname,name}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2023-02-26T12:37:03.000Z","url":"https://community.spiceworks.com/t/retrive-ad-groupmember/947056/2","author":{"@type":"Person","name":"jrp78","url":"https://community.spiceworks.com/u/jrp78"}},"suggestedAnswer":[{"@type":"Answer","text":"Hi everyone;<\/p>\n
I need your help for a request in powershell.<\/p>\n
I have a list of a few AD Groups, and i need for each group, to retrieve the members.<\/p>\n
The result i get from the cmd i used is not the the one i was expecting. It just displays all the users in those groups, without specifying which user is member of which group.<\/p>\n
Please can you tell me what is missing in my command ?<\/p>\n
$groups = Get-ADGroup -Filter * -searchBase ‘OU=SRV,OU=Accounts,DC=test,DC=NET’ -Properties name,description | where {$_.name -like ‘buil*’} | select name<\/p>\n
$ADgroupmember = $groups | ForEach-Object {Get-ADGroupMember $_.name} | select samaccountname<\/p>\n
$ADgroupmember | ForEach-Object {Get-ADUser $_.samaccountname | select name }<\/p>\n
Here is the result:<\/p>\n
Name<\/p>\n
John
\nfreddy_t2
\nGandalf_t2
\nMarvin
\nLinda
\nJohn
\nLinda_t2
\nMarvin
\nJohn
\nLinda_t2
\nfreddy_t2<\/p>\n
Big thanks in advance for your precious help.<\/p>","upvoteCount":11,"datePublished":"2023-02-26T11:57:36.000Z","url":"https://community.spiceworks.com/t/retrive-ad-groupmember/947056/1","author":{"@type":"Person","name":"tkam44","url":"https://community.spiceworks.com/u/tkam44"}},{"@type":"Answer","text":"
Get-ADGroup has a ‘members’ property.
\nSo as long as members aren’t bested you can get them all in one swoop<\/p>","upvoteCount":0,"datePublished":"2023-02-26T12:41:45.000Z","url":"https://community.spiceworks.com/t/retrive-ad-groupmember/947056/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"