Setting account expiration date

The following code sample sets the expiration date of a user account to two months from the current date.

ADSI
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Update account expiration date
$expirationDate = (Get-Date).AddMonths(2) 
$user.Put("accountExpires",$expirationDate)
$user.SetInfo()
PowerShell
Import-Module Adaxes

$identity = "jsmith" # sAMAccountName
# $identity = "CN=John Smith,CN=Users,DC=domain,DC=com"  # DN
# $identity = "{EB5FEB21-E648-42AD-B86C-89D3C6807953}" # GUID
# $identity = "S-1-5-21-573937-2149998-410785" # SID

$expirationDate = (Get-Date).AddMonths(2) 

Set-AdmUser -Identity $identity -AccountExpirationDate $expirationDate `
    -Server "domain.com" -AdaxesService localhost

The following code sample sets the expiration date of a user account to Never.

ADSI
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Update account expiration date
$user.Put("accountExpires", 0)
$user.SetInfo()
PowerShell
Import-Module Adaxes

$identity = "jsmith" # sAMAccountName
# $identity = "CN=John Smith,CN=Users,DC=domain,DC=com"  # DN
# $identity = "{EB5FEB21-E648-42AD-B86C-89D3C6807953}" # GUID
# $identity = "S-1-5-21-573937-2149998-410785" # SID

Clear-AdmAccountExpiration -Identity $identity -Server "domain.com" `
    -AdaxesService localhost

See also