简体   繁体   中英

How to find all locked Users using PowerShell

In one system there are multiple users are logged in.

I would like to know which user logged and locked the system.

I tried to find the LogonUI.exe availability. but I am not getting proper username of the LogonUI.exe

$uname = $env:UserName
$procs = @()
$allProcs = @(Get-WmiObject win32_process)
foreach($proc in $allProcs)
{
    if($proc.getowner().user -eq $uname) {
         if($proc.ProcessName() -eq LogonUI) {
              "system locked"
         }
    }
}

I tried this way. but even though user locked the system I am not getting it as locked. because it is failing at user name check. most of the time it is coming as blank. any help?

Since PowerShell 4, you can use Get-Process -IncludeUserName for getting user-names directly - as per https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process

You can also check some of the solutions on this thread too get more direct statuses from the session-manager: Powershell script to see currently logged in users (domain and machine) + status (active, idle, away)

I'm not completely sure if you are working in a domain or only on your local machine. But if perhaps you should try this out.

https://blogs.technet.microsoft.com/heyscriptingguy/2011/08/31/use-powershell-to-find-locked-out-user-accounts/

This is a post of the scripting guy from microsoft. So if your lucky this should already solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM