How to get user member of list and how to search particular group membership using PowerShell.
Example: - Suppose IntGrp group for Internet access group and need to know particular department users have access internet or not.
File Format txt. Put department user in the txt file.
$users = Get-Content c:\temp\department.txt
$output = foreach ($user in $users)
{
$groups = Get-ADPrincipalGroupMembership $user | Select Name | Where-Object name -Like "*IntGrp*"
foreach($group in $groups)
{
[PSCustomObject]@{
User = $user
Group = $group.Name
}
}
}
$output | Export-Csv c:\temp\internetaccess.csv -NoTypeInformation
No comments:
Post a Comment