How to create a local user in Windows Server using New-LocalUser PowerShell cmdlet
New-LocalUser PowerShell cmdlet can be used to create a new user in Windows Server 2025. The syntax of New-LocalUser PowerShell cmdlet is as shown below.
New-LocalUser [-AccountExpires <DateTime>] [-AccountNeverExpires] [-Description <String>] [-Disabled] [-FullName <String>] [-Name] <String> -Password <SecureString> [-PasswordNeverExpires] [-UserMayNotChangePassword] [-WhatIf] [-Confirm] [<CommonParameters>]
New–LocalUser PowerShell cmdlet is explained in below table.
Cmdlet or Parameter | What is it | Description |
---|---|---|
New–LocalUser | PowerShell cmdlet | PowerShell cmdlet to create a new local user |
–AccountExpires | Parameter | DateTime object input to specify when the user account expires. A blank –AccountExpires parameter can be used to create a local account that does not expire. |
–AccountNeverExpires | Parameter | –AccountNeverExpires parameter is used to specify that the new local account created does not expire. |
–Confirm | Parameter | –Confirm parameter is used to prompt for confirmation before executing the PowerShell cmdlet. |
–Description | Parameter | –Description parameter is used to provide a short description about the new local user. |
–Disabled | Parameter | –Disabled parameter is used to specify that the new local user account created will be in disabled state. |
–FullName | Parameter | –FullName parameter is used to specify the full name of the new local user account. |
–Name | Parameter | –Name parameter is used to specify the user name of the new local user account. |
–NoPassword | Parameter | –NoPassword parameter is used to specify that the new local user account does not have a password. |
–Password | Parameter | –Password parameter specifies a password for the user account as SecureString. |
–PasswordNeverExpires | Parameter | –PasswordNeverExpires parameter is used to specify the password for the new local user will expire. |
–UserMayNotChangePassword | Parameter | –UserMayNotChangePassword parameter is used to specify that the user cannot change the password on the user account. |
–WhatIf | Parameter | –WhatIf is used to see what will happen happen if the cmdlet runs. |
Follow below steps to create a local user in Windows Server 2025, using New–LocalUser PowerShell cmdlet.
Step 01 – First, let as define a variable as SecureString to use as the –Password parameter of the New–LocalUser PowerShell cmdlet. Read-Host -AsSecureString PowerShell cmdlet can be used to read a line of input from the console securely and masked with asterisk character. Please refer the below PowerShell cmdlet.
PS C:\jajish> PS C:\jajish> $passwdjajish = Read-Host -AsSecureString **********
Now we have defined a variable as $passwdjajish to use as the password for the new local user. The value of the new password is stored in that variable. Please refer the following screenshot.
Step 02 – Let as create a new local using the New–LocalUser PowerShell cmdlet as shown below. Please note that the input value for the -Password parameter is the variable ($passwdjajish) defined in the previous step.
PS C:\jajish> PS C:\jajish>New-LocalUser -Name "jajish" -Password $passwdjajish -FullName "Jajish Thomas" -Description "A user account for local login." -PasswordNeverExpires Name Enabled Description ---- ------- ----------- jajish True A user account for local login.
We have created a new local user, with the user name "jajish". PasswordNeverExpires parameter of the New-LocalUser PowerShell cmdlet is used to specify that the password for the new user never expires. Please refer the following screenshot.
Written by Jajish Thomas.
Last updated on 1st August, 2024.