Skip to content

Resetting computer accounts

The following code sample resets a computer account password in Active Directory.

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

# Reset password
$computerName = $computer.Get("name")
$computer.SetPassword("$computerName$")
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

$computerName = (Get-AdmComputer -Identity $identity `
    -Server "domain.com" -AdaxesService localhost).Name
$newPassword = (ConvertTo-SecureString -AsPlainText "$computerName$" -Force)

Set-AdmAccountPassword -Identity $identity -NewPassword $newPassword `
    -Reset -Server "domain.com" -AdaxesService localhost

See also