Create local user with PowerShell
- by Elizabet J
- in Powershell
- View 175
Dear reader, this tutorial is based on PowerShell 5.1 and above, which is installed on Windows 10, Windows Server 2016 and higher by default. To use this command in earlier versions, you must add the linked module to PowerShell or use the commands Use Command Prompt to create an account.
Making a Windows user with PowerShell
1. Open the PowerShell with Administrator access in Windows.
2. To create the user in PowerShell, the New-local user command is used. The structure is similar to the one below.
New-Local User -Name [username] [Option]
The New-Local User command structure is in the form of a main part called Name, which is actually the same as User name, and the other parameters that we will be explaining below.
Before explaining the various parameters, consider the following two examples to learn more about the structure of the user build command in PowerShell.
In the example below, a user is created with the name of Elizabet and no password is assigned to it, and in the Description section, an explanation is written for this user that can be customized to your liking.
New-LocalUser -Name "Elizabet" -Description "Test User" -NoPassword
In the following example, as in the first example, a user named Elizabet and Description will be created and assigned to that password. A noteworthy point in this example is that PowerShell does not accept the password in the form of a simple text, or Clear text, and you must first create a variable and enter a password, and then use the variable in the commands.
So, first enter the following command to create a variable named Password and get your password secretly.
$ password = Read-Host -AsSecureString
After entering the above command, you will receive a password that you can use after entering and pressing Inter.
New-LocalUser -Name "Elizabet" -Description "Test User with Password" -Password $ password
This way, you will be able to build the user in a parachute. Now let's take a look at the description of other application parameters mentioned.
New-Local User command parameters in PowerShell
Account Expires: User expiration date is specified with this parameter.
Account Never Expires: User account expires
Disabled: User account is disabled or disabled
Full Name: Full user name
Password Never Expires: User password expires
User May Not Change Password: The user can change the password
The following is one of the most important parameters of this command, which together with the parameters mentioned in the first and second examples, together constitute the application and specific parameters of this command. Now, in the next section, a complete example is made for the creation of an user whose application are shown below.
New-LocalUser -Name "elizabet" -Description "IT Manager" -Password $ password -FullName "Elizabet -Disabled -PasswordNeverExpires-UserMayNotChangePassword
Here is the tutorial to build the user in Windows with PowerShell.