$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 ingroup_name?
The question is why do you want to use the pipeline when just looping through the results is so easy?
To check if a user is a member of a list of groups:
And for multiple users:
Seems this question gets a lot of views, so I've updated my answer to resolve the obvious problem of the original version. This isn't a model answer and isn't the most efficient, but it accomplishes the goal.