How to set the local user account settings using PowerShell?


To set the local user account settings related to the account or the password expiration, we can use the Set-LocalUser command.

The below command will change the local user Testuser account and password set to never expire.

Set-LocalUser -Name Testuser -AccountNeverExpires -PasswordNeverExpires $true -Verbose

The below command will set the account expiry,

Set-LocalUser -Name Testuser -AccountExpires 05/11/2022 -Verbose

To run the above commands on the remote computers, use the Invoke-Command.

Invoke-Command -ComputerName Computer1, computer2 -ScriptBlock{
   Set-LocalUser -Name Testuser -AccountNeverExpires -PasswordNeverExpires $true -Verbose
}
Invoke-Command -ComputerName Computer1, computer2 -ScriptBlock{
   Set-LocalUser -Name Testuser -AccountExpires 05/11/2022 -Verbose
}

Updated on: 17-May-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements