Powershell set account expiration date

broken image
broken image

(Or of course for that single-line approach we all love:) if($expire -eq 'y') Ĭaveat: I can't quite remember what it does about time, it needs some thought about where the DateTime falls compared to midnight, but simple testing should show this. Since that will accept a DateTime rather than a number of days, you can just do: set-adaccountexpiration $userDN (get-date $expirationdate)

broken image

If you're running on Powershell v2 with the activedirectory module loaded, you can use: set-adaccountexpiration Just a thought which might simplify things for you.