Created
December 11, 2019 09:33
-
-
Save Windos/eaaf1298bd30845fb6e6d9423394d4f9 to your computer and use it in GitHub Desktop.
Group Membership Matrix Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Users = Get-ADUser -Filter 'Enabled -eq $true' | |
$GroupNames = (Get-ADGroup -Filter * | | |
Where-Object {$_.DistinguishedName -notlike '*CN=Builtin,*'}).Name | |
$Report = foreach ($User in $Users) { | |
$Groups = Get-ADPrincipalGroupMembership -Identity $User.DistinguishedName | |
$ReportProp = [Ordered] @{ | |
'Name' = $User.DisplayName | |
'Username' = $User.SamAccountName | |
'OU' = $User.DistinguishedName -replace '(CN=[\w\s-]+,){1}' , '' | |
} | |
foreach ($Group in $GroupNames) { | |
$Present = $Groups | Where-Object {$_.Name -eq $Group} | |
if ($Present) { | |
$ReportProp[$Group] = 'Member' | |
} else { | |
$ReportProp[$Group] = '' | |
} | |
} | |
[PSCustomObject] $ReportProp | |
} | |
$Report | Export-Csv -Path 'C:\Support\GroupMembershipMatrix.csv' -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment