I am using Powershell to determine the password expiry date for domain accounts. I have used the following command to get this information:
Get-ADUser -Filter {SamAccountName -eq "<username>"} -Properties "DisplayName" , "msDS-UserPasswordExpiryTimeComputed"
I then covert this value to a meaningful date by using:
[datetime]::FromFileTime(<computed filetime from above command>)
This works fine for all the domains I use, except one. In that domain I get a value of 9223372036854775807 as the msDS-UserPasswordExpiryTimeComputed. I am not able to use the FromFileTime function to convert this number into a date. It throws as error. Upon researching I have found that this number means that the password is set not to expire. However, I know that passwords do expire in this domain. Further, the PasswordNeverExpires property from the Get-ADUser cmdlet shows as False.
How can I get 9223372036854775807 from msDS-UserPasswordExpiryTimeComputed attribute and get a False from the PasswordNeverExpires property? This seems like a contradiction. What am I missing? Are there other situations when msDS-UserPasswordExpiryTimeComputed could be 9223372036854775807 too? Thanks.
The documentation lists several conditions in which
msDS-UserPasswordExpiryTimeComputedreturns9223372036854775807aka0x7fffffffffffffffaka[int64]::MaxValue(TOrefers to a given target object):Without knowing all the details, it seems that the
msDS-UserPasswordExpiryTimeComputedproperty returning0x7FFFFFFFFFFFFFFFindicates that there is effectively no password expiration, for a variety of reasons, only one of which isPasswordNeverExpiresbeing set to$True.Therefore, you could filter out such values:
It may even be possible to incorporate the test for
0x7FFFFFFFFFFFFFFFinto the-Filterargument.As an aside: Note that I've used a string rather than a script block (
{ ... }) as the-Filterargument, because using script blocks is best avoided.