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
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

>