Skip to content

Renaming user accounts

The following code sample renames 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)

# Rename the user
$user.Put("name","Ann Jones")
$user.SetInfo()
Import-Module Adaxes

$identity = "CN=John Smith,CN=Users,DC=domain,DC=com"  # DN
# $identity = "{EB5FEB21-E648-42AD-B86C-89D3C6807953}" # GUID

Rename-AdmObject -Identity $identity -NewName "Ann Jones" `
    -Server "domain.com" -AdaxesService localhost

The following code sample renames a user and modifies their logon name, First Name, Last Name, and Display Name properties.

[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)

# Update the user
$user.Put("name","Ann Jones")
$user.Put("givenName", "Ann")
$user.Put("sn", "Jones")
$user.Put("displayName", "Ann Jones")
$user.Put("userPrincipalName", "ajones@domain.com")
$user.Put("sAMAccountName", "ajones")

$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

Set-AdmUser -Identity $identity -Replace @{name='Ann Jones'} `
    -GivenName "Ann" -Surname "Jones" -DisplayName "Ann Jones" `
    -SamAccountName "ajones" -UserPrincipalName "ajones@domain.com" `
    -Server "domain.com" -AdaxesService localhost

See also