i am trying to export all the users and their membership in an excel file<\/p>\n
I looking for the following format<\/p>\n
Name GroupsMembership<\/p>\n
User1 Group1<\/p>\n
User2 group1, group2<\/p>\n
get-aduser user -Server domainname |select name, @{Name=“GroupsMembership”;Expression={(Get-ADPrincipalGroupMembership $_.DistinguishedName.ToString() -server domainname)}}<\/p>\n
I tried this but GroupsMembership is showing in a different format . can I exactly get the group name?<\/p>\n
its showing like {CN=Domain Users,OU=Security,OU=Group<\/p>\n
the reason why I mention server name is we have multiple domains.<\/p>","upvoteCount":7,"answerCount":5,"datePublished":"2020-06-16T10:18:05.000Z","author":{"@type":"Person","name":"spiceuser-yoee0","url":"https://community.spiceworks.com/u/spiceuser-yoee0"},"suggestedAnswer":[{"@type":"Answer","text":"
i am trying to export all the users and their membership in an excel file<\/p>\n
I looking for the following format<\/p>\n
Name GroupsMembership<\/p>\n
User1 Group1<\/p>\n
User2 group1, group2<\/p>\n
get-aduser user -Server domainname |select name, @{Name=“GroupsMembership”;Expression={(Get-ADPrincipalGroupMembership $_.DistinguishedName.ToString() -server domainname)}}<\/p>\n
I tried this but GroupsMembership is showing in a different format . can I exactly get the group name?<\/p>\n
its showing like {CN=Domain Users,OU=Security,OU=Group<\/p>\n
the reason why I mention server name is we have multiple domains.<\/p>","upvoteCount":7,"datePublished":"2020-06-16T10:18:05.000Z","url":"https://community.spiceworks.com/t/active-directory-user-is-a-member-of/766182/1","author":{"@type":"Person","name":"spiceuser-yoee0","url":"https://community.spiceworks.com/u/spiceuser-yoee0"}},{"@type":"Answer","text":"
Hello yoee, try this.<\/p>\n
Get-ADUser -Identity user -Properties name | select name, @{Name=\"GroupsMembership\";Expression={[string]::Join(';',(Get-ADPrincipalGroupMembership -Identity $_ | select -ExpandProperty name))}}\n\n<\/code><\/pre>\nIf you do not want to join the groups by semi-colon, just replace that with whatever you want to join by.<\/p>","upvoteCount":0,"datePublished":"2020-06-16T11:28:26.000Z","url":"https://community.spiceworks.com/t/active-directory-user-is-a-member-of/766182/2","author":{"@type":"Person","name":"jasoncramsey","url":"https://community.spiceworks.com/u/jasoncramsey"}},{"@type":"Answer","text":"
@<\/p>\n
Jasoncramsey Thanks very much , we have multiple domain. do we need to run the same for each domain? and how to get all the users of a specific domain?<\/p>\n
@jasoncramsey<\/a><\/p>","upvoteCount":0,"datePublished":"2020-06-16T12:46:46.000Z","url":"https://community.spiceworks.com/t/active-directory-user-is-a-member-of/766182/3","author":{"@type":"Person","name":"spiceuser-yoee0","url":"https://community.spiceworks.com/u/spiceuser-yoee0"}},{"@type":"Answer","text":"Yes, you could run it once for each domain, or create an array of domains then use a foreach loop to process all domains.<\/p>\n
$Domains = @('domain.com','domain.local','company.net')\nforeach ($Domain in $Domains) {Get-ADUser -Server $Domain ...}\n<\/code><\/pre>\nBut the account you are running PS as would need to have access to all the domains.<\/p>","upvoteCount":1,"datePublished":"2020-06-16T12:58:44.000Z","url":"https://community.spiceworks.com/t/active-directory-user-is-a-member-of/766182/4","author":{"@type":"Person","name":"jasoncramsey","url":"https://community.spiceworks.com/u/jasoncramsey"}},{"@type":"Answer","text":"
@jasoncramsey<\/a> <\/p>\n$Domains = @(‘domain.com<\/a>’,‘domain.local’,‘company.net<\/a>’)
\nforeach ($Domain in $Domains) {Get-ADUser -Server $Domain -Properties name,mail,enabled | select Name,Mail, Enabled, @{Name=“GroupsMembership”;Expression={[string]::Join(‘;’,(Get-ADPrincipalGroupMembership -Identity $_ | select -ExpandProperty name))}} | Export-Csv “C:\\test.csv”<\/p>\nI tried this script and got the error below and the output only has a few details.<\/p>\n
Get-ADUser : The server has returned the following error: invalid enumeration context.
\nAt line:3 char:2<\/p>","upvoteCount":0,"datePublished":"2020-06-16T14:44:53.000Z","url":"https://community.spiceworks.com/t/active-directory-user-is-a-member-of/766182/5","author":{"@type":"Person","name":"spiceuser-yoee0","url":"https://community.spiceworks.com/u/spiceuser-yoee0"}}]}}