GROUP - Report for list of users from list of AD groups
Report for list of users from list of AD groups:
$users = Get-content c:\user.txt
$groups = Get-Content c:\Groups.txt
$result = foreach($user in $userlist){
foreach($group in $grouplist){
try{
$groupmembers = Get-ADGroupMember $group -ErrorAction Stop
}
catch{
$groupmembers = $null
}
if($groupmembers.samaccountname
-match $user){
[PSCustomObject]@{
Name = $user
Group = $group
Member = 'True'
}
}
else{
[PSCustomObject]@{
Name = $user
Group = $group
Member = 'False'
}
}
}
}
$result #| export-csv "c:\result.csv"
-NoTypeInformation
Comments
Post a Comment