USER - List of users present in list of AD groups

List of users present in list of AD groups

$users = Get-content "$env:USERPROFILE\Desktop\users.txt"

$groups = Get-Content "$env:USERPROFILE\Desktop\Groups.txt"

$result = foreach($user in $users){ 

foreach($group in $groups){ 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 

"$env:USERPROFILE\Desktop\result.csv" -NoTypeInformation

Comments

Popular posts from this blog

altiris software key

Service Principal Names (SPNs) SetSPN Syntax (Setspn.exe)

Troubleshooting Netlogon Error Codes