Reputation: 40504
As topic states. How can I put 1 extra day to the selected user account.
I know AD goes by Windows File Time. Does anyone know the easiest and least code written method?
Upvotes: 2
Views: 9087
Reputation: 11
This can also be accomplished in a multi domain environment by adding the -server switch and passing in the domain string (i.e. "domain.corp.root"). I also had to move the .accountExpires as it was in the wrong place in this code sample. Thanks for providing this, it was exactly what I needed.
Import-Module ActiveDirectory
$expireDate = (Get-ADUser -Identity "samaccountname" -Properties accountExpires -server "domain.corp.root")
$renewedExpireDate = ([System.DateTime]::FromFileTime($expireDate.accountExpires)).AddDays(1)
Set-ADUser -Identity "samaccountname" -AccountExpirationDate $renewedExpireDate -server "domain.corp.root"
Upvotes: 1
Reputation: 59963
You can modify the accountExpires
property of an AD user through the Set-ADUser cmdlet included in Windows Server 2008 R2:
Import-Module activedirectory
$expireDate = (Get-ADUser -Identity "John Appleseed" -Properties accountExpires).accountExpires
$renewedExpireDate = ([System.DateTime]::FromFileTime($expireDate)).AddDays(1)
Set-ADUser -Identity "John Appleseed" -AccountExpirationDate $renewedExpireDate
As you said, the value of the accountExpires property is represented as a Windows file time, which is a 64-bit integer. In this example we convert it to a DateTime to easily modify it and then pass it to the -AccountExpirationDate
parameter to update the user.
Upvotes: 5
Reputation: 60938
Using Quest AD module:
Set-qaduser <username> -AccountExpires ( [datetime]( get-qaduser <username> -IncludeAllProperties ).AccountExpires ).AddDays(1)
Upvotes: 1