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

by Andy Grogan on May 16, 2010 · 2 comments

in Powershell, Quick Tips, Windows 2008, Windows Server 2003 (General)

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

PSIcon[1]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;

RNPS1

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;

RNPS2

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;

RNPS3

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;

RNPS4

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;

RNPS5

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.

{ 2 comments… read them below or add one }

Conrad June 2, 2011 at 7:01 pm

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

Reply

Blondinette May 29, 2014 at 8:35 am

Fantastique article, pérennise de cette façon

Reply

Leave a Comment

*

Previous post:

Next post: