Im just curious, when i create users with powershell (i also automatically generate psw’s for them) how can i set that after first log in they should change password?
Here is the code that creates users:
$container =[ADSI] $Connection
$User = $container.Create("User", "cn="+$username)
$User.Put("sAMAccountName", $username)
$User.Put("givenName", $Firstname)
$User.Put("sn", $Surname)
$User.Put("mail", $Email)
$User.SetInfo()
# Set Random Pwd and Enable Account
$User.PsBase.Invoke("SetPassword", $Password)
$User.PsBase.InvokeSet("AccountDisabled", $false)
$User.SetInfo()
To force password change at first logon add:
So the script becomes: