$groups = 'group1', 'group2'....
I need to check if the user is in a specific AD group and echo the group name if he is not ; can I do it in the pipeline?
I have googled a lot and cannot find anything, maybe I am too bad at Google search in English :).
$groups |
Get-QADGroupMember |
Get-QADUser -SamAccountName 'lalala' | ForEach-Object {
if ($_.SamAccountName -ne $null) {
Write-Host "ok"
} else {
Write-Host 'not ok'
}
}
How can I display: not ok. user is not in
group_name
?
Is @henrycarteruk answer truely the best way to acomplish that? Let's have an example: I have list of 50 groups and I want to check if user is a member of each group.
By this example:
Problems I see:
I did fast test:
My approche is below.
Have a list of groups you want to check, but you need whole DN of group.
Get user groups:
Check which groups user have: