Check if a windows user is locked out or disabled with powershell
Objective
When checking for locked out users we can issue a few different commands to check on them using powershell.
Environment
v8.0;v8.0 Beta;8.1;v8.2;v8.5;v8.6;v9.0;v9.1;v9.2;9.3;9.5;9.6;9.7;9.8;9.9;9.9.5;9.10;10.0;10.1;10.2;10.3;10.4;10.5;10.6;10.7;10.8;10.9;10.10;11.1;11
Procedure
For Active Directory, the computer using the command will need Active Directory Management tools installed. This is because we need to import the AD module to powershell that is installed with the rest of the tools.
Import-Module activedirectory
To find all locked out users for the domain, you can now issue the following command.
Search-ADAccount –LockedOut
____________Some extra fun with this command____________
Unlock all locked out accounts with a confirm required for each account:
#Note, the running user will need to be an administrator with rights to unlock accounts
Search-ADAccount -LockedOut | Unlock-ADAccount -Confirm
=====================Local Accounts=====================
For local accounts we can locally run the following to list the users for the Get-LocalUser | Select *
To list a specific account and some possible properties to see what an issue may be:
Get-LocalUser -name <TARGETUSERNAME> | Select PSComputername, Name, Status, Disabled, Enabled, AccountType, Lockout, PasswordRequired, PasswordChangeable
To remotely check local windows users, we can use WMI calls if they are available for the target and the running user has permissions on the target system.Get-WmiObject -ComputerName <Target Computer> -Class Win32_UserAccount -Filter "LocalAccount=True" | Select PSComputername, Name, Status, Disabled, AccountType, Lockout, PasswordRequired, PasswordChangeable
Lastly I like the UI of grid view and is looks a bit better then just commandline powershell.
Get-WmiObject -ComputerName <Target Computer> -Class Win32_UserAccount -Filter "LocalAccount=True" | Select PSComputername, Name, Status, Disabled, Enabled, AccountType, Lockout, PasswordRequired, PasswordChangeable | Out-GridView
We can now easily look for disabled, locked out or other accounts that may have issues on the target system.