This website uses cookies to ensure you get the best experience on our website. Learn more
PowerShell scripts to force password change for all users after a security incident
There’s plenty to do in the aftermath of your organization suffering a security incident. Anything that can make your job quicker without compromised security is a bonus. After a confirmed or even suspected security breach, it’s often advised to to have all of your end users change their Active Directory passwords. This would of course be a nightmare to manage manually, In this post, we’ll show you how to tell if end users have recently changed their passwords and share some useful PowerShell scripts that can force your end users to complete a password change in Active Directory.
Why would you need to change every user’s password?
After a security incident, an organization might want to change every user’s password to prevent further unauthorized access and to mitigate the risk of any compromised credentials being used maliciously. This proactive step helps to ensure that even if some passwords were exposed during the incident, they can no longer be used by attackers. It also helps to restore user confidence in the security of the system and can be part of a broader strategy to enhance overall security measures.
Why use PowerShell scripts to force the mass password change?
Using PowerShell scripts can make the process of changing every user’s password much easier because it automates the task, reducing the time and effort required to manage each account individually. PowerShell scripts can efficiently interact with the organization’s directory services, such as Active Directory, to generate new, secure passwords and update them across all user accounts. This automation minimizes the risk of human error, ensures consistency in the password change process, and allows IT administrators to focus on other critical security tasks. Additionally, scripts can be scheduled to run at specific times, providing a seamless and unobtrusive way to enhance security without disrupting users’ workflows.
How to find out when a password was last changed?
You can manually check the pwdLastSet attribute on each user account to see when their password was last changed (you could also find this out by running a free scan with Specops Password Auditor and looking at password changed dates in the Password Age report). Use ADSIEdit or Active Directory Users and Computers (with advanced features enabled) to view the attribute directly:
When using PowerShell to pull the attribute, you’ll see that the attribute is actually saved in what is known as ‘filetime’ format, but you can also pull a constructed attribute called passwordLastSet which will be a DateTime PowerShell attribute (more on why that’s important in a bit).
Quick note on filetime: this is a timestamp stored as a count of the number of 100-nanosecond intervals that have elapsed since midnight on January 1, 1601 (UTC).
(Last updated on February 20, 2025)
Related Articles
-
How to enforce password history in Active Directory
The “Enforce password history” setting in Active Directory is used to determine the number of unique passwords a user must use before they can use an old password again. This is an important setting because password reuse is a common issue – the more often the same (or similar) password is used, the greater chance…
Read More -
Password expiration policy best practice
Instead of arbitrarily expiring passwords every 90 or so days, why not configure the maximum password age based on the complexity level of a password?
Read More -
Helpdesk password reset best practices
If your organization is currently using a self-service password reset solution, it is critical that the helpdesk staff who manage the system, and assist users, consistently follow best practices. This post will provide tips for reducing password-related calls to the helpdesk, and outline some security measures for safeguarding user accounts. Educate and direct to self-service…
Read More