Powershell: Set users in a OU with a default password and set to require to change password

Hi All,

I am wondering how to create a Powershell script that I can execute for a OU that will:

 - Create a default password
 - require that the user has to change their password when they login for the first time

I also need to create one that does the same thing but does not force the users to change their password

Thank you for all of your help in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy LidbetterCommented:
Hi Thomas,

You can use the following Powershell command:
$Users = Get-ADUser -Filter * -SearchBase "ou=users,dc=domain,dc=com" -SearchScope 2 | Select DistinguishedName
Foreach ($User in $Users) {
	Set-ADAccountPassword -Identity $User.DistinguishedName  -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "New_Password" -Force)
	Set-ADUser -Identity $User.DistinguishedName -ChangePasswordAtNextLogon $true

Open in new window

to explain it:

Searchbase is the OU you would like to run the script against.
Searchscope 2 means that it will do all Child OU's of the specified OU as well.

The -Reset parameter means you don't have to provide the OriginalPassword and will force a reset.

To prevent the force reset on next logon, just change the "Set-Aduser" cmdlet to $false ... i.e.
$Users = Get-ADUser -Filter * -SearchBase "ou=users,dc=domain,dc=com" -SearchScope 2 | Select DistinguishedName
Foreach ($User in $Users) {
	Set-ADAccountPassword -Identity $User.DistinguishedName  -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "New_Password" -Force)
	Set-ADUser -Identity $User.DistinguishedName -ChangePasswordAtNextLogon $false

Open in new window



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thomasm1948Author Commented:
Excellent thank you for all of your help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.