Search code examples
powershellactive-directory

Active Directory ADUser whenCreated Property


I've created (Server 2019) an ADUser: TestUser100.

New-ADUser -name TestUser100

This user has a property: whenCreated ("11.05.2021 15:00:00"), when I try to find the user:

Get-ADUser -filter{whenCreated -eq "11.05.2021 15:00:00"} -properties whenCreated

I've got nothing, when I search after: Created it works, why?

Get-ADUser -filter{Created -eq "11.05.2021 15:00:00"} -properties Created

Solution

  • The whenCreated attribute is stored as string in AD with this format 20111101000413.0Z. (zulu format)

    When you compare that to another string 11.05.2021 15:00:00, the result will be $false.

    PowerShell conveniently maps that attribute to property Created, which is the whenCreated string converted to a Datetime object.
    Because in your filter Created is on the left side of the equation, the string you give it is converted by PowerShell to a Datetime object and all compares as you expect.

    BTW -Filter is a string, not a scriptblock, so should be

    "Created -eq '11.05.2021 15:00:00'"