Please wait,
Processing your request...

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

React: Postcard image. Click this to mail to Johan


ICT-Hotlist Topic

Back to the ICT-Hotlist...
Don't miss latest updates Follow @WebHalla

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 - 2023 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.6 : Friday 2-6-2023 © Copyright 1995-2023 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 overcast clouds
Temperature 11.63 °C overcast clouds
Wind chill 10.78 °C overcast clouds
Humidity 74 % overcast clouds
Air pressure 1021 hPa overcast clouds
Wind speed 5.14 m/s overcast clouds
Wind direction North North overcast clouds
Sun Rise 5:27 Sun Rise
Sun Set 21:45 Sun Set
Updated:2023-06-02 01:08:14 overcast clouds

Weather Cache is 8 minute(s) old.