I need to get specific users from specific Groups in Active Directory.
So far I have this:
$Groupnames = get-adgroup -Filter "name -like '$Groupfilter'" -Properties * -SearchBase $Grouppath | Select-Object Name, @{ Name='Username'; Expression={ Get-ADGroupMember -identity $($_.Name) -Recursive | Get-ADUser -Property SamAccountName | Select -ExpandProperty SamAccountName } } This works to get the Groups with their names. Now I want to get all users from these groups. what works but the formating is completly off. I want this:
Name Username ---- -------- Group1 user1adm Group2 {user1adm, user1, user2, user2adm...} Group3 {user1adm, user3, user2adm, user6...} But I get this:
{user1adm, user1, user2, user2adm...} With that formatting I can't see all users.
My goal at the end is also to exclude users who end with adm, but I don't know how to do that.
Can you help me?
Select NametoSelect -Expand Name{user1, user1adm, user2, user3...}Why is there{}and...at the end. It doesn't show the rest of the users.{}are not a huge problem, I can get rid of them. But that it doesn't show all users is the bigger Problem.