Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Set 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: 2021-05-17T12:51:03+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements