JDwum4
JDwum4

Reputation: 37

Adding days to an ADUsers AccountExpirationDate

Please Note: I am a newbie to Powershell

I would like to Get an ADusers AccountExpirationDate and Add 90days to the AD user's Expiration Date. Tried the

Get-ADUser -Identity $username | Set-ADAccountExpiration -TimeSpan 90.0:0

However, it adds 90 days to the current day under the AD user's account. Is there a way to specify adding 90 days to an ADUser AccountExpirationDate?

Upvotes: 1

Views: 828

Answers (1)

Santiago Squarzon
Santiago Squarzon

Reputation: 60370

I think this works. If I understand correctly, you want to add 90 days to the current value of AccountExpirationDate.

$usr = Get-ADUser -Identity $username -Properties AccountExpirationDate
$newExp = $usr.AccountExpirationDate.AddDays(90)

Set-ADAccountExpiration -Identity $usr -DateTime $newExp

Upvotes: 1

Related Questions