Powershell : Updating DisplayName to "Firstname Surname"

This will update the DisplayName attribute from "LastName, FirstName" to "FirstName Surname" this means:

"Croucher, Lee" will become "Lee Croucher"

WARNING: Please do not just run scripts from the internet without checking them and ensuring you know what they are doing, this could break you domain or user logins, this script will write/change attributes to your domain

This is the script that will do that magic - as below, all you need to do is update the details in bold.

# Import the Active Directory module
Import-Module ActiveDirectory

# Get the OU to target
$ou = Get-ADOrganizationalUnit -Identity "OU=NameSwitchers,DC=bear,DC=local"

# Get all users in the OU
$users = Get-ADUser -Filter * -SearchBase $ou

# Update the displayname and CN of each user
foreach ($user in $users) {
    # Set the displayname
    Set-ADUser -Identity $user -DisplayName "$($user.GivenName) $($user.Surname)"

# Write a confirmation message
Write-Host "The displayname and CN of all users in the OU '$($ou.Name)' have been updated."

Previous Post Next Post

Ω†Ω…ΩˆΨ°Ψ¬ Ψ§Ω„Ψ§ΨͺΨ΅Ψ§Ω„