Learn how to Create a user in Windows with PowerShell step by step. Usually most Windows users have accidentally struggled with CMD or Command Prompt at least once and know that CMD or Command Prompt is used to execute Windows commands. But few people know what PowerShell is and how it works. In this article, we will teach you how to create a user in Windows with PowerShell. PowerShell is a tool like Command Prompt that is much more complex and powerful than Command Prompt and is supposed to replace Command Prompt altogether. Because PowerShell’s ability and control over Windows is much greater than Command Prompt.
This tutorial is based on PowerShell version 5.1 and above, which is installed by default on Windows 10 and Windows Server 2016 and above. To use this command in older versions, you must add the relevant module to the PowerShell or use the Command Prompt command to create a user. Join us now to learn how to create a user in Windows with PowerShell.
Tutorial create a user with PowerShell commands
Windows PowerShell follows a comprehensive structure, and knowing that you have worked with PowerShell will make it very easy to learn how to create a user build in PowerShell.
1- First open PowerShell with Administrator access in Windows.
2- To create a user in PowerShell, the New-localuser command is used, the structure of which is similar to the following.
New-LocalUser -Name [username] [Option]
The structure of the New-LocalUser command is such that it has a main section called Name, which is actually the username and other parameters that we will explain below.
Example to create a user in Windows with PowerShell
Before explaining the various parameters, pay attention to the following two examples to get more familiar with the structure of the user command created in PowerShell.
In the example below, a user named Michael is created and no password is assigned to it, and in the Description section, a description is written for this user that can be customized as you wish.
New-LocalUser -Name “Michael” -Description “Test User” -NoPassword
In the following example, as in the first example, a user with a specific username Michael and Description will be created and assigned a password. The important point in this example is that PowerShell does not accept the password as a simple type or Clear text, and you must first create a variable and enter the password in it, and then use the variable between commands.
Enter the following command to create a variable called Password and receive it from you secretly.
$password = Read-Host -AsSecureString
After entering the above command, you will receive a password. After pressing Enter, you can also use the following command.
New-LocalUser -Name “Michael” -Description “Test User with Password” -Password $password
This will allow you to create a user in PowerShell. We will now go on to describe the other practical parameters mentioned.
New-LocalUser command parameters in PowerShell
AccountExpires: The user’s expiration date is specified by this parameter
AccountNeverExpires: User account expired or not
Disabled: The user account is active or inactive
FullName: Full username
PasswordNeverExpires: User password expires or not
UserMayNotChangePassword: The user can change the password or not
The items mentioned are important parameters of this command, which along with the parameters mentioned in the first and second examples, together constitute the practical and specific parameters of this command.
Below is a complete example of creating a user. In this example, see the use of parameters.
New-LocalUser -Name “Michael” -Description “IT Manager” -Password $password -FullName “Michael Jordan-Disabled -PasswordNeverExpires –UserMayNotChangePassword
We tried to teach you how to create a user in Windows with PowerShell with practical examples. It was also mentioned New-LocalUser command parameters in PowerShell.