sync server time ntp

Adding a new user in Windows through command-line by Bas Wijdenes

Introduction “Add a user in Windows“.

You can add a new user to windows via the command-line in different ways.

You can add a user in Windows via PowerShell, but you can also add a user to windows with Command Prompt.


Let’s add a new user to windows with Command Prompt.

Before we start. Make sure you are logged in with an administrator account that has enough permissions to create a new user.

Command Prompt can be found under start.
Go to start and search for Command prompt,
or press CTR + R and type in CMD.

Command Prompt is now opened.

Type or copy / then paste this line into Command Prompt, but make sure that your nameofuser changes to the desired username and change password to the user password.

net user nameofuser password /add

And a few extra commands after adding a user with command-line.

And to make the user administrator you can use the following command.
Don’t forget to change nameofuser to the desired username.

net localgroup Administrators nameofuser /add

And to reset a user password, you can use the following command.

net user nameofuser password2

And to remove a user, you can use the following command.

net user nameofuser /delete

For more about Command Prompt, please go to Wikipedia.


Let’s add a new user to windows with PowerShell.

Go to start and search for PowerShell, or PowerShell_ISE.
You can also press CTRL + R and then type in PowerShell, or PowerShell_ISE.

PowerShell only shows the command line. In PowerShell_ISE you can create scripts and execute them. So if you copy and paste the scripts below into PowerShell_ISE, you can easily adjust them.

To add a user via PowerShell, you must first secure the password.

This can be done in advance in different ways.

A safe way is to use

$password = Read-host-AsSecureString

So as a complete command you can use this. Make sure that you change the username.

$Password = Read-Host -AsSecureString

New-LocalUser username -Password $Password -FullName ‘New User’ -Description ‘This is the user description’

To change the password of the user you can use this command:

$Password = Read-Host -AsSecureString
Set-LocalUser username -Password $password

And to make the user administrator you can use this command.

Add-LocalGroupMember -Group Administrators -Member username

For more about New-LocalUser, please go to Technet.

For more about PowerShell, please go to Wikipedia.


Summary

It’s nice to see that this is one of my first blog posts. It is almost shameful when I look back at it. How could I think that this blog post would attract people? Ah well, I’ve reviewed the blog post and the content is still relevant, so I’ve adjusted it until I’m satisfied with it. Although I do not expect many people to find this blog post.

I have also been very generous with my tags 😉!

Adding a new user in Windows through command-line.
Adding a new user in Windows through command-line.

A little extra

This post contains PowerShell. Would you like to learn the basics better? I have created a new website to learn basic PowerShell in an ’emulator’ environment.
Click here to go learn Basic PowerShell.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

Leave a Reply

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