i tried to get the ADGroups of all users in the domain. basically i want to do an
$users = Get-ADUser -All $true
>>
>> $report = Foreach ($user in $users) {
>> $groups = $user | Get-ADUserMembership
>>
>> # create output objects with username and groups:
>> Foreach ($group in $groups) {
>> [PSCustomObject][ordered]@{
>> UserDisplayName = $user.DisplayName
>> UserPrincipalName = $user.UserPrincipalName
>> GroupDisplayName = $group.DisplayName
>> }}}
>>
>> # print a table with desired formatting
>> $report | ft
but the parameter -all doesnt exist for Get-ADUser. does anyone had this problem and maybe found a solution?
CodePudding user response:
Did something simelar, you need to get the root Domain with get-adforest. In our company the root Domain consists of 2 Layers, so for such an example you can use: Get-ADUser -filter * -searchBase "DC=Layer2,DC=Layer1"
CodePudding user response:
This one did it.
$users = Get-ADUser -filter *
>>
>> $report = Foreach ($user in $users) {
>> $groups = $user | Get-ADPrincipalGroupMembership
>>
>> # create output objects with username and groups:
>> Foreach ($group in $groups) {
>> [PSCustomObject][ordered]@{
>> UserDisplayName = $user.SamAccountName
>> UserPrincipalName = $user.UserPrincipalName
>> GroupDisplayName = $group.name
>> }}}
>>
>> # print a table with desired formatting
>> $report | Export-Csv -NoTypeInformation -Encoding Default -Force c:\temp\adusergroups.csv