Rename Local Administrator Account during OSD using PowerShell

During OS Deployment it's not entirely uncommon to see organizations renaming the local admin directly in the task sequence. There are many options available for doing so, but using a healthy dose of PowerShell is an effective way. 🙂

Using the Rename-LocalUser Cmdlet

Below sample gets hold of the local administrator account from its well-known SID, and then renames that account by piping the object to the Rename-LocalUser cmdlet.

 $NewAdminName = "Demo1"
 Get-LocalUser | Where-Object { $_.SID -like "S-1-5-*-500" } | Rename-LocalUser -NewName $NewAdminName

Simply add the above script to your task sequence, no need for a package, but don't forget to set the PowerShell execution policy to Bypass.

A Windows 11 Task Sequence configured with an action for renaming the local admin account.
About the author

Johan Arwidmark

0 0 votes
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
Steve Gear
Steve Gear
2 months ago

Hi Johan! We are having an issue lately where the Local Admin Account is getting disabled before MDT LiteTouch Deployment finishes. After the First Reboot of applying the image, it reboots as it normally would and we expect it to login with the local admin account but it gives us a message instead that the local administrator account is disabled. This did not used to happen and the only thing I can think of that has changed is we updated the build of Windows 10 that we are deploying to the 22H2.18 from our VLSC downloads. Any Help here would… Read more »