PowerShell change AD displayname

While helping a peer at a Junior College clean up a their Active Directory I wrote this one liner to set the Display Name field uniformly for all of their accounts. It just takes every AD account with a specific UPN and sets display name to Last, First for each user based on what they already have in AD for Given Name and Surname.

We start out with a Get-AdUser searching the entire domain and filtering on a specific UPN, the filter should be changed to whatever criteria your environment has or just * to pickup everyone. Then we’ll specify the three properties of Given Name (first), Surname (last), and Displayname. That is | into a foreach loop and Set-ADuser based on samAccountName (which comes from the Get-ADuser command) and changes -displayname to be First Comma Last. Remove the whatif at the end once you are ready to go prime time in your environment and make the changes.

Leave a Reply

Your email address will not be published. Required fields are marked *