Change AD Display name from Lastname, Firstname to Firstname Lastname
My organization wants to change the Display name format to Firstname Lastname
instead of Lastname, Firstname
I already change the format for creating new users in the ADSI settings. But want to change all current users display name to Firstname Lastname
I found a script in: Default full name format in Active Directory
Get-ADUser -LDAPFilter "(&(objectCategory=person)(!displayName=*,*)(displayName=*))" |
ForEach-Object {
Set-ADUser $_ -DisplayName "$($_.Surname), $($_.givenName)"
}
This change it from Firstname Lastname
to Lastname, Firstname
. I want to do a reverse, so I tweak this script to:
Get-ADUser -LDAPFilter "(&(objectCategory=person)(!displayName=*,*)(displayName=*))" |
ForEach-Object {
Set-ADUser $_ -DisplayName "$($_.givenName) $($_.Surname)"
}
But my AD users have still a display name like Lastname, Firstname
. PS do not give any warnings or errors and did a refresh in AD.
Do someone knows a trick to change all AD users to Firstname Lastname
as Displayname?
Solution 1:
The problem is the filter. The string (!displayName=*,*)
indicates that only user who currently don't have a ,
in their displayname should be changed. You want the inverse, so you need to remove the !
.
Get-ADUser -LDAPFilter "(&(objectCategory=person)(displayName=*,*))" |
ForEach-Object {
Set-ADUser $_ -DisplayName "$($_.givenName) $($_.Surname)"
}