Powershell – New-ADuser force to change password at next logon

active-directorypowershellwindows-server-2012-r2

I want to use Powershell New-ADuser to add new user in that, new user must have change password at first time logon. I find the attribute "-ChangePasswordAtLogon" but when I use it, new user still not enable option change password at first time login.

New-ADUser -Name "Nguyen Van Nam" -GivenName "Nguyen Van" -Surname Nam -SamAccountName namnv -UserPrincipalName namnv@queencenter.local -ChangePasswordAtLogon 1 -AccountPassword (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -PassThru | Enable-ADAccount

Best Answer

We had to do this recently for all our users. Essentially something like:

$myUser = Get-ADUser [your filter or search parameters; embed in a foreach if you need to]
$myUser.pwdLastSet = 0
Set-ADUser -Instance $myUser

This will do the trick.