Updating AD Usernames to FirstName.LastName format

Here’s a quick script for updating usernames from whatever format they’re in at the moment to a firstname.lastname format, based on their current First Name  and Last Name attributes in Active Directory.

The script can be used a few different ways – first, let’s have a quick look at how it can be used against a single user, firstly in test mode:

.\Update-Username.ps1 -Username steve -UPNSuffix exchangelabs.co.uk -WhatIf


Then for real by removing the –WhatIf parameter:


Next, let’s have a look how it can be used en-mass. We’ll create a text file with a list of users:


Then use the Get-Content cmdlet to suck in our users.txt file and user a foreach loop to test the command against all the users in that file. We’ll also log to a file called changes.txt:

Get-Content .\users.txt | foreach { .\Update-Username.ps1 –Username $_ –UPNSuffix exchangelabs.co.uk -LogFile .\changes.txt -WhatIf }


As before, we can run the script again without –Whatif and make the changes proposed for real:


Download the script from the Technet Gallery..

3 thoughts on “Updating AD Usernames to FirstName.LastName format

  1. Quick question – does this attempt to change the Pre-Windows 2000 username or just the logon account – some of our users will have UPN that exceed the 16(?) character limitation for the Pre-2000 username in that case.

  2. Hi Steve,

    Cracking piece of work this. Can you tell me, rather than using a text file can you read a list of users straight from an OU and then pipe the resulting output into the script to modify them?

Comments are closed.