Get-ADUser -Filter command

Glenn Maxwell 10,146 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 Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,457 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,371 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,854 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} votes

Accepted answer
  1. rafalzak 3,216 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 43,931 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