Enabling and disabling computer accounts

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

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 computer
$computerDN = "CN=MYCOMPUTER,CN=Computers,DC=domain,DC=com"
$computer = $service.OpenObject("Adaxes://$computerDN", $null, $null, 0)

# Enable the computer account
$computer.AccountDisabled = $false
$computer.SetInfo()

# Disable the computer account
$computer.AccountDisabled = $true
$computer.SetInfo()
PowerShell
Import-Module Adaxes

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

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

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

See also