• Home
  • About 404TS
  • Contact

404 Tech Support

Where IT Help is Found

  • Articles
    • Code
    • Entertainment
    • Going Green
    • Hardware, Gadgets, and Products
    • Management
    • Network
    • News
    • Operating Systems
    • Security and Privacy
    • Software
    • System Administration
    • Talking Points
    • Tech Solutions
    • Web
    • Webmaster
  • Reviews
  • Media
    • Infographics
    • Videos
  • Tech Events
  • Tools
    • How do I find my IP address?
    • Browser and plugin tests
  • Get a Technical Consultation
You are here: Home / Articles / Code / PowerShell script to query AD for number of accounts with expired passwords

PowerShell script to query AD for number of accounts with expired passwords

2016-06-20 by Jason

With a recent change to our password policy, some users’ passwords began expiring more frequently than before. This has had our phone support seeing an increase in calls. In order to monitor the situation, we wanted to see numbers for those groups regarding how many accounts had expired passwords and were another potential phone call.

This script is written with a function for easy code re-use. In the example script, I am querying two different collections of users as they are separated into different OUs in our AD. You could use just one query at the top to find all users but for my purpose, the split was helpful. I suppose you could add more logic to determine users by group membership rather than solely by OU. To query more groups, just reproduce the line:

query [FriendlyNameOfGroup] “Distinguished name of OU in AD where these users (and only these users) reside”

The script calls the function and determines all users that are enabled and do not have a policy setting “password never expires”. It then determines how many of that total are currently expired, including a percentage. We also look 30 days out to see how many more users will expire in the next 30 days based on the msDS-UserPasswordExpiryTimeComputed attribute. As we have been communicating the change to users and directing them to change their password, we should hopefully start seeing that number decrease.

The output then shows the total number of users in that group, the number and percentage of those with expired passwords, and the count of those with passwords that will expire in 30 days.

It’s a pretty simple script but provided good experience querying AD, performing calculations, and formatting output.

https://gist.github.com/jhamilton09/17ba2b8a899718bd95e9b216aeb734f5

Filed Under: Code Tagged With: powershell

Trending

  • Resolve Internet Explorer Slowly Opening New Tabs
    In Software, Tech Solutions
  • #MicrosoftEDU introduced Windows 10 S, the new Surface Laptop, and Microsoft Teams for classrooms
    In Hardware, Gadgets, and Products
  • Windows System Control Center – All Your Windows Utilities In One Portable App
    In Software, Tech Solutions

Latest Media Posts

Find Out Where To Download SNES ROMs

Find Out Where To Download SNES ROMs

Multifunctional Video Conversion Tools – Wondershare Video Converter

Multifunctional Video Conversion Tools – Wondershare Video Converter

  • Popular
  • Latest
  • Today Week Month All
  • Wal-Mart’s Low Tech Solution to a Shocking Problem Wal-Mart's Low Tech Solution to a Shocking Problem
  • Access to the resource [servershare] has been disallowed Access to the resource [servershare] has been disallowed
  • What is the AllJoyn Router Service on Windows 10? What is the AllJoyn Router Service on Windows 10?
  • Read the Event Logs on Windows Server Core Read the Event Logs on Windows Server Core
  • Increase IIS Private Memory Limit to improve WSUS availability Increase IIS Private Memory Limit to improve WSUS availability
  • How Virtual Reality Supports Mental Health Therapy How Virtual Reality Supports Mental Health Therapy
  • Key Strategies of Successful Coin Listing on Exchange Key Strategies of Successful Coin Listing on Exchange
  • Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting
  • Making Distributed Software Development Work: Strategies and Best Practices for Managing Remote Teams Making Distributed Software Development Work: Strategies and Best Practices for Managing Remote Teams
  • customer contactless payment for drink with mobile phon at cafe counter bar,seller coffee shop accept payment by mobile.new normal lifestyle concept The Latest Innovations In Payment Technology
Ajax spinner

Elevator Pitch

404 Tech Support documents solutions to IT problems, shares worthwhile software and websites, and reviews hardware, consumer electronics, and technology-related books.

Subscribe to 404TS articles by email.

Recent Posts

  • How Virtual Reality Supports Mental Health Therapy
  • Key Strategies of Successful Coin Listing on Exchange
  • Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting

Search

FTC Disclaimer

404TechSupport is an Amazon.com affiliate; when you click on an Amazon link from 404TS, the site gets a cut of the proceeds from whatever you buy. This site also uses Skimlinks for smart monetization of other affiliate links.
Use of this site requires displaying and viewing ads as they are presented.

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in