ChangePasswordAtLogon for LocalUser

Viewed 4050

I found this post helpful. PowerShell - User Must Change Password at Next Logon

Is it possible to force a user to set a password on next sign in by using something like this?

Set-LocalUser -ChangePasswordAtLogon:$true

I get a NamedParameter error when trying the script above.

What's the best way to force a local user account to reset a password upon login?

2 Answers

The Set-LocalUser cmdlet does not have a parameter ChangePasswordAtLogon

Try

Set-LocalUser -Name "TheUser" -PasswordNeverExpires $false

or use

$user = [ADSI]"WinNT://$env:ComputerName/TheUserName,user"
$user.PasswordExpired = 1
$user.SetInfo()

From how it looks, the Set-LocalUser doesn't have a force password change, the post you referenced is for ActiveDirectory users. Looking at this SuperUser post, there is a workaround using net user and wmic that you could code in PowerShell to emulate it:

Here's what I found worked for me on Windows 10 Home.

wmic UserAccount where name='John Doe' set Passwordexpires=true

Followed by

net user "John Doe" /logonpasswordchg:yes

Related