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:
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:
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.