Sometimes there is a need to set an exact time for an account to expire in active directory. But the RSAT visual tools do not allow you to set a specific time. So I had a question. Is there a way to do this? It turns out there is a way! But it requires some PowerShell to make it work.
Here is the simple PowerShell script I made to set an active dirctory account expiration time for me.
#Get User Name $username = Read-Host 'Enter Username:' $datetime = Read-Host 'Enter Expire Date in time in this format (12/17/2018 11:00:00)' #Set Expire Date and Time. Set-ADAccountExpiration -Identity $username -DateTime $datetime #Check account. Get-ADUser -Identity $username -Properties AccountExpirationDate | Select-Object -Property SamAccountName, AccountExpirationDate
This script just asked for a username and the expire time. Then it saves them into some variables. Then it runs the PowerShell command to set that expire time. After that it runs the command to check the expire time so we can make sure it got set.
I like to keep things simple so there is nothing more to this script. But it gets the job done. This would also make a good foundation if you want to modify it to do more!