Question on Search-ADAccount

Mikhail Firsov 1,881 Reputation points
2022-06-03T10:37:30.66+00:00

Hello!

On more question on quering AD in PS, please:

According to Search-ADAccount the -DateTime parameter can be used for both -AccountExpiring and -PasswordExpired, but the -DateTime + -PasswordExpired would always raise the error, both in AD2008R2 and AD2022 - is it a bug in Search-ADAccount or incorrect documentation?

208140-q5-expired.png

Thank you in advance,
Michael

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-06-03T15:02:30.127+00:00

    If you use the -PasswordExpired switch you cannot use the -DateTime parameter. The password has either expired or it hasn't. Perhaps you're reading the -PasswordexpirED as if it were -PasswordExpirING?

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Mikhail Firsov 1,881 Reputation points
    2022-06-06T12:58:07.373+00:00

    "Perhaps you're reading the -PasswordexpirED as if it were -PasswordExpirING?" - the ability to use the -DateTime along with -PasswordexpirED does realy turn "-PasswordexpirED" into "-PasswordExpirING" and I would have never thought about it if I hadn't seen the documentation above.

    "The password has either expired or it hasn't. " - agree.

    "If you use the -PasswordExpired switch you cannot use the -DateTime parameter." - as you see the article Search-ADAccount says you can.

    Am I getting it right that "If you use the -PasswordExpired switch you cannot use the -DateTime parameter. means documentation error?

    Regards,
    Michael


  2. Mikhail Firsov 1,881 Reputation points
    2022-06-07T10:28:35.757+00:00

    The set you mentioned is correct, but I referenced this:

    "-DateTime
    Specifies a distinct time value for Search-ADAccount parameters such as AccountExpiring, AccountInactive, and PasswordExpired."

    • and this obviously is not correct :(

    Thank you for the help!

    Regards,
    Michael


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.