Powershell

How to Use the New-LocalUser (Microsoft.PowerShell.LocalAccounts) Cmdlet in PowerShell?

Windows users can create a new account using GUI-based “Control Panel” settings. However, PowerShell can also be utilized for that corresponding purpose. PowerShell’s “New-LocalUser” cmdlet is used for creating a new local and remote user account on Windows. For such a cause, PowerShell needs to be launched with administrator access.

This post will provide the usage of the “New-LocalUser” cmdlet in PowerShell.

How to Use the New-LocalUser (Microsoft.PowerShell.LocalAccounts) Cmdlet in PowerShell?

To create a new user on Windows, specify the “New-LocalUser” cmdlet and then provide it with the username to be created. Further, parameters can be added to create an account with customized options. Let’s overview the provided examples to get further knowledge regarding the stated cmdlet.

Example 1: Use the “New-LocalUser” Cmdlet to Create an Account
Execute the below-stated command to create a new user account:

New-LocalUser -Name "User1" -Description "New account is created successfully." -NoPassword

In accordance with the stated command:

  • First, specify the “New-LocalUser” cmdlet to create a new local user.
  • Then, write the “-Name” parameter to provide it with the new user account name.
  • Next, mention the “-Description” parameter to write the description of the account.
  • Lastly, provide the “-NoPassword” parameter to avoid adding the password for the account:

Example 2: Use the “New-LocalUser” Cmdlet to Create a Password Protected User Account
To create a password-protected user account, use the below-given command:

$Password = Read-Host -AsSecureString
New-LocalUser "New_User" -Password $Password -FullName "New User" -Description "This account is password protected"

In the above-stated code:

  • First of all, initialize a variable and specify it in the “Read-Host” cmdlet to read the input.
  • Also, specify the variable the “-AsSecureString” parameter to take the password as secure input.
  • Then, in the next line, write the “New-LocalUser” and provide it with the new local username.
  • Next, add the “-Password” parameter and specify the above-mentioned variable to take and store the password.
  • After doing so, mention the “-FullName” parameter to write the new username and also the “-Description” parameter to add a description for the account:

That’s all! You have successfully learned the method to create a new user in PowerShell using the “New-LocalUser” cmdlet.

Conclusion

PowerShell’s “New-LocalUser” cmdlet creates a new local, or remote user account in Windows. It creates a user account/profile connected to a Microsoft account. This post has demonstrated the procedure to create a new user account using the “New-LocalUser” cmdlet in PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.