Powershell to Expire Groups of people

John Davies
John Davies used Ask the Experts™
on
Password expiration by groups of Username.

What I am looking for is a powershell script or help with one that I can run and expire a group of people from a csv file. So for example

People with the surname beginning with A to E then F to I and so on......

I would populate the spreasheet but just need to expire people passwords in groups rather than expiring everyone in one hit. The reason i am wanting this I am implementing a new password policy and as we have over 2500 users I would rather expire them and have them change the password on next login in chunks on a weekely basis.

Thanks

John
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018
Commented:
This will get all the users which SamAccountName starts with an "a" until "f", you can safely test on your environment

Get-ADUser -LDAPFilter "(&(sAMAccountName>=a)(sAMAccountName<=f))"

Open in new window



Then you just need to pipe the command that makes him expire the password:
 Get-ADUser -LDAPFilter "(&(sAMAccountName>=j)(sAMAccountName<=k))" |Set-ADUser -ChangePasswordAtLogon

Open in new window

Author

Commented:
Sorry Jose, forgot to mention that this is a pure cloud office 365 solution, no on prem or hybrid.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial