Powershell v2.0 Script to Rename Local and Remote Machine User Accounts…

One of the things that I do once I have built a server is to re-name the default Administrative Account on the local machine (which I am sure is common amongst most of you) .
I have been meaning for a while to write a Script in Powershell which accomplishes the above task (rather than relying on either manual methods or indeed a trusty VBScript) – but until recently I have not had the chance to sit down a compose one.

In this article I would like to share with you a sample Powershell v2.0 script which can rename accounts on either a local or remote machine (as long as both machines are running Powershell v2.0 and have Windows Remote Management enabled to accept remote management requests).

If you would like to make use of the script download it (below) to a suitable location on your computer, open a Powershell Window (make sure that the Execution Policy for Scripts is at least “RemoteSigned” – for information on how to accomplish this see here) and then navigate to the location where you have stored the script and type in .\RenameLocalandRemoteUserAccounts.ps1


Upon the scripts execution you will be asked if you would like to rename a local user account (e.g. one which resides on the machine where the script has been executed from – or an account on a remote host) – to proceed – type in either “l” for local or “r” for remote.
The remainder of this article will be based around if you have chosen to use the remote mode (as it contains some additional steps – but the process of renaming the account is exactly the same as if you were working in remote mode) – see below;


If you have opted to work on a remote machine – you will be asked to provide the NETBIOS domain name of your target machine – after confirming your choice by pressing – you will be presented with a dialog box requesting session logon credentials – you will need to ensure that the account which you provide has administrative rights on the target machine – see below;


The script will then enumerate all of the local accounts on the machine that you have requested and present them to you as a numbered list – see below;


Choose the number of the account that you would like to rename – then when asked provide a value for the new name of the account – see below;


Press the key and the script will then rename the account – you will be presented with a “Script Completed” message when processing is completed – see below;


I hope that someone finds this little script useful – during my research I found a number of scripts which were similar; but could not find one quite like it with all the functionality that I wanted so I hope the source code will help give others an idea.

Sharing is caring!:

One thought to “Powershell v2.0 Script to Rename Local and Remote Machine User Accounts…”

  1. Quick question, when you encapsulate a variable in two + signs what does that do exactly? For instance lines 22 and 33 of this script.

Leave a Reply

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