Home » PowerShell » How to Create Local User Account Using PowerShell

How to Create Local User Account Using PowerShell

To create a local user account using PowerShell, use the `New-LocalUser` command. This command creates a local user account.

Here, is the PowerShell command to create a local user account.

New-LocalUser
   [-AccountExpires <DateTime>]
   [-AccountNeverExpires]
   [-Description <String>]
   [-Disabled]
   [-FullName <String>]
   [-Name] <String>
   -Password <SecureString>
   [-PasswordNeverExpires]
   [-UserMayNotChangePassword]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

In this article, we will discuss how to create a local user account, create a local user account that has a password.

How to Create a Local User Account Using PowerShell

Use the New-LocalUser command to create a new local user account.

New-LocalUser -Name 'Peter Ambler' -Description 'Description of this account.' -NoPassword

In the above PowerShell script, the New-LocalUser creates a new local user account “Peter Ambler“. It doesn’t specify the AccountExpires or Password parameters. The local user account doesn’t expire or have a password.

The output of the above PowerShell script to create a local user account is given below.

Create a New Local User Account
Create a New Local User Account

How to Create a New Local User Account that has a Password

To create a new local user account that has a password, use the New-LocalUser cmdlet with the Password parameter.

$Password = Read-Host -AsSecureString
$params = @{
    Name        = 'James Allen'
    Password    = $Password
    Description = 'Description of this account.'
}
New-LocalUser @params

In the above PowerShell script, firstly, the Read-Host cmdlet prompts you to enter a password and stores it as a secure string in the $Password variable. $params variable stores the local user account details such as Name, Password, and Description.

Lastly, the New-LocalUser command uses the $params to create a local user account that has a password.

The output of the above PowerShell that creates a local user account with a password is given below.

$Password = Read-Host -AsSecureString
$params = @{
    Name        = 'James Allen'
    Password    = $Password
    Description = 'Description of this account.'
}
New-LocalUser @params

Name        Enabled Description
----        ------- -----------
James Allen True    Description of this account.


PS C:\>

Conclusion

I hope the above article on how to create a new local user account using the New-LocalUser PowerShell command is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Related Links

Microsoft.PowerShell.LocalAccounts Module

Get-LocalGroupMember

Get-LocalUser

Add-LocalGroupMember

Enable-LocalUser

Disable-LocalUser

Rename-LocalUser

Set-LocalUser