I have some code so far, but would like it to result in a table with multiple lines for users per group.
Currently, it creates a table like this:
Group | Users |
---|---|
abcgroup1 | Alice |
abcgroup1 | Bob |
abcgroup2 | Bob |
abcgroup2 | Jason |
abcgroup3 | Eve |
I would like it to instead create a table like this:
Group | Users |
---|---|
abcgroup1 | Alice Bob |
abcgroup2 | Bob Jason |
abcgroup3 | Eve |
$Groups = get-adgroup -Filter 'name -like "*abc*"'
$Results = foreach( $Group in $Groups ){
Get-ADGroupMember -Identity $Group | foreach {
[pscustomobject]@{
Group = $Group.Name
Users = $_.Name
}
}
}
$Results
$Results | Export-Csv C:\abc_search.txt -NoTypeInformation