Please wait,
Processing your request...

  Business logo
  ... | Selecteer de Nederlandse taal |
Sharing is caring
| Print this page. | Linkedin page of Johan van Soest

React: Postcard image. Click this to mail to Johan


ICT-Hotlist Topic

Find locked out Windows Domain Users with PowerShell

Have some colleagues that use BYOD with their own (e-mail) synchronised programs? Changing their Windows passwords on their desktop, notebook or even through a Citrix portal results in log on problems? Then one of their devices might be using an old password to synchronise, resulting in an Active Directory user account lockout.
This PowerShell script determines if someone is locked out from the Active Directory Domain Services (AD DS), and when the situation occurred. It reports :
   No-one locked out
or a list formatted as:
  Name  Since               Locked Out
  Johan 2015-11-16 22:29:37 True
Using this script on a Windows 7, 8 or 10 desktop? You may need to load the Active Directory module by configuring RSAT. Read more about RSAT here
# This PowerShell script determines if someone is locked out from the
# Active Directory, and when the situation occurred:
# It reports
#    No-one locked out
# or a list of:
#    Name  Since               Locked Out
#    Johan 2015-11-16 22:29:37 True
# (C)Copyrights 2015 - 2024 by J. van Soest.

# Load the Active Directory PowerShell module.
Import-Module ActiveDirectory
# Clear the screen so the data is nicely presented.
"This PowerShell script determines if someone is locked out from the "
Write-Host "Active Directory, and when the situation occurred:"

# Define an object and load it with all the users currently locked out
$LOUsers = Search-ADAccount -lockedout

# Check if the object contains any members
if ( $LOUsers -ne $null ) {
# Object contains members so write the table headers on the screen (tab seperated)
    Write-Host "Name`tSince`tLocked Out"
# Now loop through all the members and write data to screen tab formatted.
    foreach ($LOUser in $LOUsers){
        $Usr = Get-ADUser $LOUser -Properties *
        $Time = $Usr.lockoutTime
# Format the Active Directory date number using the filesystem datetime object
        $strTime = [datetime]::FromFileTime($Time).ToString("yyy-MM-dd HH:mm:ss")
        Write-Host $Usr.Name,"`t",$strTime,"`t",$Usr.lockedout

# The object is empty. So no one is locked out.
    Write-Host "No-one locked out"

Want to test this script? Just run the command line interface (cli) command:
runas /user:%userdomain%\<testuser> cmd.exe
Run it 5 times (substitute the retries lock out value of your domain), with a test user account and fill in a wrong password each time. The PowerShell script will show a locking of the <testuser> account.

Account Lockout Status (LockoutStatus.exe)

Microsoft also has a tool called LockoutStatus that does not require PowerShell and has a GUI. Read more here
You may vote your opinion about this article:

Scripts and programming examples disclaimer

Unless stated otherwise, the script sources and programming examples provided are copyrighted freeware. You may modify them, as long as a reference to the original code and hyperlink to the source page is included in the modified code and documentation. However, it is not allowed to publish (copies of) scripts and programming examples on your own site, blog, vlog, or distribute them on paper or any other medium, without prior written consent.
Many of the techniques used in these scripts, including but not limited to modifying the registry or system files and settings, impose a risk of rendering the Operating System inoperable and loss of data. Make sure you have verified full backups and the associated restore software available before running any script or programming example. Use these scripts and programming examples entirely at your own risk. All liability claims against the author in relation to material or non-material losses caused by the use, misuse or non-use of the information provided, or the use of incorrect or incomplete information, are excluded. All content is subject to change and provided without obligation.
Generated by WebHalla™ Version 0.1.e.7 : Thursday 30-5-2024 © Copyright 1995-2024 ing. Johan P.G. van Soest CIPM Certified Privacy Information Manager
Response Form    Cookie- and Privacy statement    Responsible Disclosure procedure
Weather in Waalre by OpenWeatherMap logo few clouds
Temperature 9.66 °C few clouds
Wind chill 9.22 °C few clouds
Humidity 94 % few clouds
Air pressure 1006 hPa few clouds
Wind speed 1.54 m/s few clouds
Wind direction South South few clouds
Sun Rise 5:28 Sun Rise
Sun Set 21:43 Sun Set
Updated:2024-05-30 05:08:18 few clouds

Weather Cache is 8 minute(s) old.
| Current user: Guest | Login |