Please wait,
Processing your request...

    0%
  Business logo VanSoest.it  
  ... | Selecteer de Nederlandse taal | Print this page. | Linkedin page of Johan van Soest | User: Guest | Login

Postcard image. Click this to mail to Johan

WebHalla
 Content
  Management
   System


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 - 2019 vanSoest.it by J. van Soest.


# Load the Active Directory PowerShell module.
Import-Module ActiveDirectory
# Clear the screen so the data is nicely presented.
cls
Write-Host
"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
    }

}
else{
# 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:


Topic created  :  01-05-2017
Topic last edited  :  31-05-2018

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.3 : Thursday 14-11-2019 © Copyright 1995-2019 ing. Johan P.G. van Soest CIPM Certified Privacy Information Manager
Response Form    Cookie- and Privacy statement
Weather in Waalre by OpenWeatherMap logo overcast clouds
Temperature 5.52 °C overcast clouds
Humidity 93 % overcast clouds
Air pressure 1003 hPa overcast clouds
Wind speed 1.5 m/s overcast clouds
Updated:2019-11-14 21:23:05 overcast clouds

Weather Cache is 2 minute(s) old.