Filtering multiple users with get-aduser
active-directory, powershell
Solution
You'd probably want to put this into a function:
$dummydata = @('Bill','Joe','Sam')
$filter =
[scriptblock]::create(($dummydata| foreach {"(GivenName -eq '$_')"}) -join ' -or ')
Get-ADUser -f $filter
Problem
I'm new to powershell and have to fetch users from AD based on a list with names. Is there any way to filter from AD using something similar to an in-statement in SQL? (select * from users where name in ('Joe','Bill)? As for now I fetch users in a foreach loop and add them to an arraylist, but I don't know if this is good practice: ``` function GetUsers() { $dummydata = @('Bill','Joe','Sam') $users = New-Object System.Collections.ArrayList($null) foreach($user in $dummydata) { $aduser = get-aduser -f {GivenName -eq $user} -Properties * | select * $users.add($aduser) | Out-Null } Return ,$users } ```