Get-ADUser -Filter command

Glenn Maxwell 12,876 Reputation points
2022-10-10T10:29:17.337+00:00

Hi All

i have 5 employee ids, i want to know whether they exists in AD or not. experts guide me how to pull the information.

12345
12346
12347
12348
12349

if i use the below syntax i believe it gives me all the employee ids but i dont want all.

Get-ADUser -Filter * -Properties *| select -property EmployeeID,DisplayName,Title,userprincipalname

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. rafalzak 3,251 Reputation points
    2022-10-10T11:00:45.14+00:00

    Hi @Glenn Maxwell ,

    Please try something like this:
    Get-ADUser -Filter "EmployeeID -eq 12345" -Properties * | select -property EmployeeID,DisplayName,Title,userprincipalname

    Please upvote or accept as answer if it helped.


1 additional answer

Sort by: Most helpful
  1. Limitless Technology 44,766 Reputation points
    2022-10-11T15:43:23.487+00:00

    Hello there,

    Here's one quick way:

    ([ADSISearcher] "(sAMAccountName=kendyer)").FindOne()
    If it returns no results, the user account was not found.

    As a function:

    function Test-ADUser {
    param(
    [Parameter(Mandatory = $true)]
    [String] $sAMAccountName
    )
    $null -ne ([ADSISearcher] "(sAMAccountName=$sAMAccountName)").FindOne()
    }

    ------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.