Last active
October 3, 2021 12:32
-
-
Save Techlogist/962aa21658e9ab3f86cd3a3346b528f2 to your computer and use it in GitHub Desktop.
How to audit user's AD group membership?
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
# License: GNU General Public License v2.0 | |
# Author: Miguel | |
# Website: www.techlogist.net | |
# Post: https://techlogist.net/powershell/how-to-audit-users-ad-group-membership/ | |
# Description: Audit user’s AD group membership | |
# OS/Language/Region: Windows/EN-US | |
$User_List= "C:\Users\Administrator\Desktop\Users.txt" | |
$Group_List= "C:\Users\Administrator\Desktop\Groups.txt" | |
$Output_CSV= "C:\Users\Administrator\Desktop\GroupsInfo.CSV" | |
$Users= Get-Content $User_List | |
$Groups= Get-Content $Group_List | |
foreach ($user in $Users) { | |
foreach ($group in $Groups) { | |
$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty SamAccountName | |
If ($members -contains $user) { | |
"$user;$group;Present;"|Add-Content $Output_CSV -Encoding UTF8 | |
} Else { | |
"$user;$group;Not Present;"|Add-Content $Output_CSV -Encoding UTF8 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment