Home » PowerShell » How to Modify a Local User Account using PowerShell

How to Modify a Local User Account using PowerShell

To modify a local user account in PowerShell, use the `Set-LocalUser` command. This command modifies a local user account and can reset the password of a local user account.

Here, is the PowerShell code to modify a local user account.

Set-LocalUser
   [-AccountExpires <DateTime>]
   [-AccountNeverExpires]
   [-Description <String>]
   [-FullName <String>]
   [-InputObject] <LocalUser>
   [-Name] <String>
   [-Password <SecureString>]
   [-PasswordNeverExpires <Boolean>]
    [-SID] <SecurityIdentifier>
   [-UserMayChangePassword <Boolean>]

In this article, we will discuss how to update a local user account description and reset the local user account password using the PowerShell Set-LocalUser command.

Change Description of Local User Account Using PowerShell

To change the description of a local user account, use the PowerShell command Set-LocalUser. This command uses the Name parameter to specify the local user account and the Description parameter to specify a new description for a local user account.

Set-LocalUser -Name "nathan" -Description "EU HR Divison"

In the above PowerShell script, the Set-LocalUser cmdlet changes the local user account description specified in the Description parameter to “EU HR Division“.

To check if the user account description is modified or not, use the Get-LocalUser command as given below.

 Get-LocalUser -Name "nathan"

The output of the above PowerShell script gets the local user account details including his name, enable status, and description.

Modify Description of Local User Account
Modify Description of Local User Account

How to Reset the Password of a Local User Account in PowerShell

The Set-LocalUser command in PowerShell can be used to reset the local user account password.

$Password = Read-Host -AsSecureString
$UserAccount = Get-LocalUser -Name "Peter Ambler"
$UserAccount | Set-LocalUser -Password $Password

In the above PowerShell script, firstly the Read-Host cmdlet prompts you to enter a password and store it as a secure string in the $Password.

The next command uses the Get-LocalUser to get the local user account using its name “Peter Ambler” and store it in the $UserAccount variable.

Lastly, the Set-LocalUser command sets the new password on the local user account stored in $UserAccount.

Conclusion

I hope the above article on how to use the Set-LocalUser command in PowerShell to change the description of a local user account and reset the user password 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

Add-LocalGroupMember

Get-LocalUser

Get-LocalGroupMember

New-LocalUser

Enable-LocalUser

Rename-LocalUser

Disable-LocalUser