User accounts set to expire

Use the following PowerShell to find User's expiration status & dates.

The Attribute:

The LDAP attribute we are interested in here is "AccountExpires". This field contains a time string formatted in NT Epoch time. (See "Accounts that will Expire" below to convert it.)

You can use the following PowerShell to select it:
Get-ADUser -Identity "JHeisler" -Properties ("AccountExpires")

Accounts set to "Never" expire:

If the "AccountExpires" attribute contains "9223372036854775807" or "0" that indicates that the user's account is set to never expire.

Accounts that will expire:

If an account is set to expire, (i.e. "AccountExpires" attribute does not contain "9223372036854775807" or "0") We can convert it using w32tm.exe with the /ntte [AccountExpires] argument. See Below:

Lets say the "AccountExpires" attribute contains 133002945050000000. We can convert this to a readable date using the following command:

w32tm.exe /ntte 133002945050000000

Witch will output:
 
153938 14:15:05.0000000 - 06/21/2022 10:15:05

So we can see this user account will expire on 6/21/2022 at 10:15

Function to Set expiration to 90 Days from current date:

Needed to write this for My work, thought I'd share it. Its basically the Set-ADAccountExpiration with some extra logic.

Comments

Popular posts from this blog

Create Profiles for Managing Microsoft Exchange using Windows Terminal (Online and On-Prem)

Give a User 'SendAs' permssions to a Mail-Enabled AD Group in Exchange Online

Get a User's Active Directory Groups