Skip to content

Creating computer accounts

The following code sample create a new computer account 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 container
$containerDN = "CN=Computers,DC=domain,DC=com"
$container = $admService.OpenObject("Adaxes://$containerDN", `
    $NULL, $NULL, 0)

# Create a new compuer object
$computer = $container.Create("computer", "CN=NEWCOMPUTER")

[Softerra.Adaxes.Interop.Adsi.PersistentObjects.ADS_USER_FLAG_ENUM]$accountOptions =
    "ADS_UF_WORKSTATION_TRUST_ACCOUNT, ADS_UF_PASSWD_NOTREQD"
$computer.Put("userAccountControl", [Int32]$accountOptions)

# Save the computer account to the directory
$computer.SetInfo()
Import-Module Adaxes

$containerDN = "CN=Computers,DC=domain,DC=com"

New-AdmComputer -Name "NEWCOMPUTER" -SamAccountName "NEWCOMPUTER" `
    -Path $containerDN -Server "domain.com" -AdaxesService localhost

See also