Hi All<\/p>\n
I have an AD group, it has many subgroups and users, for example
\nGroup1 is my AD group. it has many groups and users added to it, i want to export users and groups residing in it to csv file.
\nLets say Group1 has below groups and users and i want the output as in the below format.( i dont want to export all users of group2 and group4, i just need the group names)<\/p>\n
Group2
\nuser1
\nuser2
\ngroup4<\/p>\n
i am using below two syntaxes and i am not getting output.<\/p>\n
Get-ADGroupMember -Identity \"group1\" | Get-ADUser -Properties Name,Description,UserprincipalName,SamAccountName,office,Department | Select Name,Description,UserprincipalName,SamAccountName,office,Department | Export-CSV -Path C:\\temp\\output.csv -NoTypeInformation\n\nor\n\n$props = \"Name,Description,UserprincipalName,SamAccountName,office,Department,ObjectCategory\" -split ',' \n(Get-ADGroup -Identity \"group1\").Members | \nSelect-Object @{n=Identity;v={$_}} |\nGet-ADObject -Properties $props | \nSelect-Object $props | Export-CSV -Path C:\\temp\\output.csv -NoTypeInformation\n\n<\/code><\/pre>","upvoteCount":7,"answerCount":2,"datePublished":"2021-11-04T07:58:22.000Z","author":{"@type":"Person","name":"Glenn-Maxwell","url":"https://community.spiceworks.com/u/Glenn-Maxwell"},"acceptedAnswer":{"@type":"Answer","text":"Something like this works but keep in mind, groups don’t have the same attributes available as users.<\/p>\n
$members = Get-ADGroupMember -Identity \"groupname\" \n$results = foreach($member in $members){\n if($member.objectclass -eq 'user'){Get-ADUser $member -Properties Name,Description,UserprincipalName,SamAccountName,office,Department | Select Name,Description,UserprincipalName,SamAccountName,office,Department}\n elseif($member.objectClass -eq 'group'){Get-adgroup $member -Properties Name,Description,UserprincipalName,SamAccountName,Department | Select Name,Description,UserprincipalName,SamAccountName,Department}\n }\n$results | Export-CSV -Path C:\\temp\\output.csv -NoTypeInformation\n\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2021-11-04T08:30:56.000Z","url":"https://community.spiceworks.com/t/get-adgroupmember-syntax/815945/2","author":{"@type":"Person","name":"jrp78","url":"https://community.spiceworks.com/u/jrp78"}},"suggestedAnswer":[{"@type":"Answer","text":"Hi All<\/p>\n
I have an AD group, it has many subgroups and users, for example
\nGroup1 is my AD group. it has many groups and users added to it, i want to export users and groups residing in it to csv file.
\nLets say Group1 has below groups and users and i want the output as in the below format.( i dont want to export all users of group2 and group4, i just need the group names)<\/p>\n
Group2
\nuser1
\nuser2
\ngroup4<\/p>\n
i am using below two syntaxes and i am not getting output.<\/p>\n
Get-ADGroupMember -Identity \"group1\" | Get-ADUser -Properties Name,Description,UserprincipalName,SamAccountName,office,Department | Select Name,Description,UserprincipalName,SamAccountName,office,Department | Export-CSV -Path C:\\temp\\output.csv -NoTypeInformation\n\nor\n\n$props = \"Name,Description,UserprincipalName,SamAccountName,office,Department,ObjectCategory\" -split ',' \n(Get-ADGroup -Identity \"group1\").Members | \nSelect-Object @{n=Identity;v={$_}} |\nGet-ADObject -Properties $props | \nSelect-Object $props | Export-CSV -Path C:\\temp\\output.csv -NoTypeInformation\n\n<\/code><\/pre>","upvoteCount":7,"datePublished":"2021-11-04T07:58:23.000Z","url":"https://community.spiceworks.com/t/get-adgroupmember-syntax/815945/1","author":{"@type":"Person","name":"Glenn-Maxwell","url":"https://community.spiceworks.com/u/Glenn-Maxwell"}}]}}