Reputation: 71
I'm trying to change the name parameter of a user in Active Directory. I have tried the below code but it's not working. The error is always "the name parameter is not known":
Import-Module ActiveDirectory
$oldName = "OldUserName"
$newName = "NewUserName"
$user = Get-ADUser -Identity $oldName
Set-ADUser -Identity $user -Name $newName
Upvotes: 2
Views: 172
Reputation: 174815
To change the name
attribute of an AD object, use Rename-ADObject
:
Import-Module ActiveDirectory
$oldName = "OldUserName"
$newName = "NewUserName"
$user = Get-ADUser -Identity $oldName
$user |Rename-ADObject -NewName $newName
Upvotes: 2