PowerShell command to unlock, reset, and set password change on next login (on-premise)

IT 140 Reputation points
2023-12-18T11:52:53.0766667+00:00

PowerShell command template for a junior IT employee in my small charity school.

We have a hybrid environment, but as I have been informed by the previous system admin that it is recommended to rest the password on-prem than from the admin portal. is it correct?

I need assistance with developing a command that can unlock, reset, and set a password change on next login for on-premise server 2019 using the following information as an example:

Username: John cloud OU: year-12 Login: jcloud@@school.edu.uk

Can anyone help please?

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Thameur-BOURBITA 36,261 Reputation points Moderator
    2023-12-18T15:43:08.6066667+00:00

    Hi @IT

    #To unlock user account
    Unlock-ADAccount -Identity jcloud
    #To reset user password
    Set-ADAccountPassword -Identity 'jcloud' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "p@ssw0rd" -Force)
    #Force user to change his password at first logon
    Set-Identity 'jcloud' -ChangePasswordAtLogon $true
    

    You can refer to the following links to get more details:

    Set-ADUser

    Unlock-ADAccount

    Set-ADAccountPassword


    Please don't forget to accept helpful answer


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.