Skip to content

Enabling and disabling user accounts

The following code sample shows how to enable and disable a user account.

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

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

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

# Enable the user account
$user.AccountDisabled = $False
$user.SetInfo()

# Disable the user account
$user.AccountDisabled = $True
$user.SetInfo()
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

# Enable the user account
Enable-AdmAccount -Identity $identity -Server "domain.com" -AdaxesService localhost

# Disable the user account
Disable-AdmAccount -Identity $identity -Server "domain.com" -AdaxesService localhost

See also