Hi everyone.<\/p>\n
I’m looking for a basic script that has two parts:<\/p>\n
output all the groups in AD<\/p>\n<\/li>\n
take that output and query group memberships for each group and output everything to a CSV file.<\/p>\n<\/li>\n<\/ol>\n
Any help would be greatly appreciated!<\/p>","upvoteCount":3,"answerCount":8,"datePublished":"2018-01-17T16:24:23.000Z","author":{"@type":"Person","name":"martinsaunders7874","url":"https://community.spiceworks.com/u/martinsaunders7874"},"acceptedAnswer":{"@type":"Answer","text":"
I guess this could work: https://community.spiceworks.com/topic/1472794-how-to-table-all-ad-groups-and-members-of-each-group-then-export-to-csv-psscript<\/a><\/p>","upvoteCount":1,"datePublished":"2018-01-17T16:53:45.000Z","url":"https://community.spiceworks.com/t/powershell-script-listing-users-and-groups/629222/5","author":{"@type":"Person","name":"thomasblhmann7922","url":"https://community.spiceworks.com/u/thomasblhmann7922"}},"suggestedAnswer":[{"@type":"Answer","text":" Hi everyone.<\/p>\n I’m looking for a basic script that has two parts:<\/p>\n output all the groups in AD<\/p>\n<\/li>\n take that output and query group memberships for each group and output everything to a CSV file.<\/p>\n<\/li>\n<\/ol>\n Any help would be greatly appreciated!<\/p>","upvoteCount":3,"datePublished":"2018-01-17T16:24:23.000Z","url":"https://community.spiceworks.com/t/powershell-script-listing-users-and-groups/629222/1","author":{"@type":"Person","name":"martinsaunders7874","url":"https://community.spiceworks.com/u/martinsaunders7874"}},{"@type":"Answer","text":" what have you tried so far? Where are you stuck? Errors?<\/p>\n If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>","upvoteCount":0,"datePublished":"2018-01-17T16:25:53.000Z","url":"https://community.spiceworks.com/t/powershell-script-listing-users-and-groups/629222/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":" I’ve run this script: (found here on Spiceworks using the search feature With the following command:<\/p>\n It works fine. However, the output doesn’t tell me how to distinguish a Distribution Group from a Security group.<\/p>","upvoteCount":0,"datePublished":"2018-01-17T16:46:12.000Z","url":"https://community.spiceworks.com/t/powershell-script-listing-users-and-groups/629222/3","author":{"@type":"Person","name":"martinsaunders7874","url":"https://community.spiceworks.com/u/martinsaunders7874"}},{"@type":"Answer","text":" That script works however differently than what you asked in the OP, the script you found queries the group membership of each user.<\/p>\n It does not find all groups and then it’s members.<\/p>","upvoteCount":1,"datePublished":"2018-01-17T16:48:48.000Z","url":"https://community.spiceworks.com/t/powershell-script-listing-users-and-groups/629222/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":" Try this<\/p>\n not a script, but check out this tool Cjwdev | AD Permissions Reporter<\/a><\/p>\n from<\/p>\n\n
<\/p>\n
Param (\n [Parameter(Mandatory=$true,ValueFromPipeLine=$true)]\n [Alias(\"ID\",\"Users\",\"Name\")]\n [string[]]$User\n)\nBegin {\n Try { Import-Module ActiveDirectory -ErrorAction Stop }\n Catch { Write-Host \"Unable to load Active Directory module, is RSAT installed?\"; Break }\n}\n\nProcess {\n ForEach ($U in $User)\n#Get-ADUser -Filter {Enabled -eq \"True\"}\n { $UN = Get-ADUser $U -Properties MemberOf\n $Groups = ForEach ($Group in ($UN.MemberOf))\n { (Get-ADGroup $Group).Name\n }\n $Groups = $Groups | Sort\n ForEach ($Group in $Groups)\n { New-Object PSObject -Property @{\n Name = $UN.Name\n Group = $Group\n }\n }\n }\n}\n<\/code><\/pre>\n
Get-ADUser -Filter {Enabled -eq $true} -SearchBase \"ou=XX,dc=XX,dc=ca\" | .\\Get-UserGroupMemberships.ps1 | Export-CSV d:\\UserMembers.csv\n<\/code><\/pre>\n
Get-ADUser -Filter {Enabled -eq $true} -SearchBase \"ou=XX,dc=XX,dc=ca\" -Properties DisplayName,memberof | % {\n New-Object PSObject -Property @{\n\tUserName = $_.DisplayName\n\tGroups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join \",\"\n\t}\n} | Select UserName,Groups |Sort-Object -Property Name| Export-Csv C:\\treport.csv -NTI\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2018-01-17T17:05:52.000Z","url":"https://community.spiceworks.com/t/powershell-script-listing-users-and-groups/629222/6","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"