Powershell command to require a new password

@xlnvis 21 Reputation points
2022-12-22T19:26:53.13+00:00

Hello, I am trying to make a PowerShell script for work to require local users not on a domain to change their password on logon.
I am currently using 'net user $localAccount /passwordchg:yes /logonpasswordchg:yes' which does require them to change passwords on next login, however they can just set their new password to the same as their old password. I was wondering if there was any way to make it so they cant reuse their old password as their new, if anyone happens to know please let me know. Thanks

Microsoft 365 and Office Development Office JavaScript API
0 comments No comments
{count} votes

Accepted answer
  1. Jordan Millama 1,386 Reputation points
    2022-12-22T20:11:21.923+00:00
    net accounts /uniquepw:5  
    

    This will make it that users are unable to re-use their last 5 passwords.

    273463-image.png

    ----------

    Please accept as an answer if this was helpful.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ali AlEnezi 1,081 Reputation points
    2022-12-22T20:09:06.69+00:00

    Hello,

    Yes, it is possible to prevent users from reusing their old password as their new password when changing it in a PowerShell script. Here are a few different approaches you can try:

    1. Use the net user command with the /passwordreq:yes option: This option requires users to set a new password that meets the complexity requirements of the password policy. This can help prevent them from setting their new password to the same as their old password.
    2. Use the Set-LocalUser cmdlet with the -PasswordNeverExpires parameter: This cmdlet allows you to set the PasswordNeverExpires property of a user account to $true, which means that the user's password will never expire. This can be useful if you want to prevent users from changing their password, which would also prevent them from reusing their old password as their new password.
    3. Use a custom script: You could also create a custom script that checks the user's new password against their old password (or a list of old passwords) and prevents them from setting it to a password that they have used before. This approach would require more work to implement, but it could provide more control and flexibility in enforcing password reuse policies.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.