New LocalUser - PowerShell
Overview
The New-LocalUser cmdlet in PowerShell allows you to create a new local user account on the computer. It is a versatile tool for user management, often used for adding new users, configuring user permissions, and managing user access.
Syntax
New-LocalUser [-Name] <string> [-Password] <SecureString> [-DisplayName] <string> [-Description] <string> [-Enabled] <bool> [-Force] [-Group] <string[]> [-GroupMembership] <string[]> [-HomeDirectory] <string> [-HomeDrive] <string> [-LocalAccount] [-NoPassword] [-Path] <string> [-ProfilePath] <string> [-ResetPassword] [-Server] <string> [-SID] <string> [-Status] <string> [-Unload] [-WhatIf] [-Confirm]
Options/Flags
-Name: The username for the new local user account.-Password: The password for the new user account.-DisplayName: The display name for the new user account.-Description: A description of the new user account.-Enabled: Specifies whether the new user account is enabled or disabled.-Force: Overwrites an existing user account with the same name.-Group: The security groups to which the new user will be added.-GroupMembership: The security groups from which the new user will be removed.-HomeDirectory: The home directory path for the new user account.-HomeDrive: The home drive letter for the new user account.-LocalAccount: Creates a local user account instead of a domain user account.-NoPassword: Creates the new user account without a password.-Path: The path to the user profile for the new user account.-ProfilePath: The path to the user profile for the new user account.-ResetPassword: Resets the password for the new user account.-Server: The computer on which to create the new user account.-SID: The SID for the new user account.-Status: The status of the new user account.-Unload: Unloads the user profile for the new user account.-WhatIf: Shows what would happen if the command were executed without actually executing it.-Confirm: Prompts for confirmation before executing the command.
Examples
Example 1: Create a new local user account named “user1” with a password of “Password1”
New-LocalUser -Name user1 -Password (ConvertTo-SecureString -String "Password1" -AsPlainText -Force)
Example 2: Create a new local user account named “user2” with a description of “New User” and add it to the “Users” group
New-LocalUser -Name user2 -Description "New User" -Group Users
Example 3: Create a new local user account named “user3” with a home directory of “C:\Users\user3” and a home drive of “Z:”
New-LocalUser -Name user3 -HomeDirectory "C:\Users\user3" -HomeDrive Z:
Common Issues
- Error creating user: Ensure that you have sufficient permissions to create user accounts on the computer.
 - User account already exists: If you try to create a user account with a name that already exists, you will encounter an error. Use the 
-Forceoption to overwrite the existing account. - Invalid password: The password must meet the complexity requirements set by the local security policy.
 
Integration
New-LocalUser can be combined with other PowerShell commands for more advanced user management tasks. For example:
- Get a list of all local user accounts:
 
Get-LocalUser
- Disable a local user account:
 
Disable-LocalUser -Name <username>
Related Commands
- Get-LocalUser
 - Disable-LocalUser
 - Remove-LocalUser