Renaming AD accounts

We occasionally need to rename an AD user. Adoptions, marriage or mistakes are the most common reasons.

You can’t update all attributes using Active Directory. The steps for renaming a user are as follows.

Run the following powershell script to update the AD account and Office 365 username. You will need to manually update the username, email, and employeeid fields shown inside parentheses. Do not include the parentheses.

import-module activedirectory
 
import-module msonline
 
connect-msolservice

 
#Update Active Directory
 
$user = get-aduser "(username)"

 
#Change display name, and company name
set-aduser $user -displayname "(First Last)" -SamAccountName (username) -UserPrincipalName (username)@granvilleschools.org -ErrorAction SilentlyContinue
rename-ADObject -identity $user -Newname "(First Last)"

#Update Office 365
$user = get-aduser -properties employeeid -filter {employeeid -eq "(employeeid)"}
$onlineUsers = Get-MsolUser -SearchString $user.Name

if ($onlineUsers.count -eq 1){
 
if ($user.UserPrincipalName -ne $onlineUsers.userprincipalName)
 
{ Set-MsolUserPrincipalName -ObjectId $onlineUsers.ObjectId -NewUserPrincipalName $user.UserPrincipalName

}

}

The second step is to manually rename the user in Google. You can do this manually through the admin console.

The third step is to update their email addresses through Exchange. As a practice we keep the old email addresses in addition to the new addresses unless the account name change was caused by a simple mistake.