• 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

  • fm transmitter plugged inFM Transmitters – Give your old car the gift of Bluetooth
    In Articles, Hardware, Gadgets, and Products, Reviews
  • 5 Ways IoT Is Revolutionizing the Call Center Industry
    In Tech Solutions
  • Tuning In To The Debate Of Mandating FM Radio In Your Phone
    In Hardware, Gadgets, and Products, News

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
  • How to ‘Unblock’ multiple files at a time with PowerShell How to 'Unblock' multiple files at a time with PowerShell
  • Increase IIS Private Memory Limit to improve WSUS availability Increase IIS Private Memory Limit to improve WSUS availability
  • Read the Event Logs on Windows Server Core Read the Event Logs on Windows Server Core
  • SOLVED: “This modification is not allowed because the selection is locked.” SOLVED: "This modification is not allowed because the selection is locked."
  • Command line to take ownership and change permissions Command line to take ownership and change permissions
  • 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
  • How Digital Technology Brought the Rise of the CMO   How Digital Technology Brought the Rise of the CMO  
  • How to Purchase Cryptocurrencies? How to Purchase Cryptocurrencies?
  • Top 6 necessary aspects to consider when hiring Angular developers Top 6 necessary aspects to consider when hiring Angular developers
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

  • Making Distributed Software Development Work: Strategies and Best Practices for Managing Remote Teams
  • The Latest Innovations In Payment Technology
  • How Digital Technology Brought the Rise of the CMO  

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 © 2023 · Magazine Pro Theme on Genesis Framework · WordPress · Log in