Advance

How to Create a user in Windows with PowerShell

How to Create a user in Windows with PowerShell

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.

Note: The CMD or Command Prompt commands work in PowerShell environment, and you can also use the CMD user command to create a PowerShell user.

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.

Recommended Article: How to change the MAC address in Windows

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.

Example 1:

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  

Example 2:

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  

Conclusion

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.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

10 thoughts on “How to Create a user in Windows with PowerShell

    1. The Invoke-Command command can help you execute your command in any situation. For example, you want to execute a command from a remote control. In this case, you can enter the following command by default:
      Invoke-Command –ScriptBlock {Get-EventLog System –Newest 50}

  1. I have a file called Services.htm and now I want to change it to a new name, MyServices.txt. By what order in PowerShell is it possible to change the name?

    1. The Remove-Item command is responsible for deleting various items, files, and registry keys.
      Suppose we want to delete a file that we renamed in the previous command from our folder. In this case, you must enter the command because in PowerShell to achieve the final result, ie deleting the item:
      Remove-Item “C:\MyData\MyServices.txt

Leave a Reply

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

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day