Notice: Due to size constraints and loading performance considerations, scripts referenced in blog posts are not attached directly. To request access, please complete the following form: Script Request Form Note: A Google account is required to access the form.
Disclaimer: I do not accept responsibility for any issues arising from scripts being run without adequate understanding. It is the user's responsibility to review and assess any code before execution. More information

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

نموذج الاتصال