简体   繁体   English

如何使用PowerShell查找所有锁定的用户

[英]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. 我试图找到LogonUI.exe的可用性。 but I am not getting proper username of the LogonUI.exe 但我没有得到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 从PowerShell 4开始,您可以按照https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process使用Get-Process -IncludeUserName直接获取用户名。

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) 您还可以检查此线程上的某些解决方案,也可以从会话管理器中获取更多直接状态: Powershell脚本以查看当前登录的用户(域和计算机)+状态(活动,空闲,离开)

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/ 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. 这是Microsoft脚本专家的帖子。 So if your lucky this should already solve your problem. 因此,如果幸运的话,这应该已经解决了您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Powershell为组织单位中的所有用户替换说明文本 - How to Replace Description Text for All Users in an Organizational Unit using Powershell 查找使用Powershell登录到Access数据库的用户 - Find users logged into Access database using Powershell 如何使用 powershell 以编程方式查找用户 HKEY_USERS 注册表项? - How can I programmatically find a users HKEY_USERS registry key using powershell? powershell查找所有组的所有用户标志为禁用 - powershell find all users for all groups flag as disabled 使用 powershell 删除锁定的文件 - Delete a locked file using powershell 如何使用 powershell 找到文件夹内的所有空子文件夹? - How to find all the empty subfolders inside the folder using powershell? Powershell - ActiveDirectory 为 OU 中的所有用户查找 LastLogon 和 Manager - Powershell - ActiveDirectory Find LastLogon and Manager for all users in OU 如何比较用户和 OU 中的用户,然后使用 Powershell 添加用户 - How to compare users and users in an OU then add the users using Powershell 如何使用 PowerShell 在 SharePoint 上在线向所有站点 collections 报告用户权限 - How get users permissions report to all site collections on SharePoint Online using PowerShell 如何使用powershell脚本将文件复制到C:Users目录中的所有桌面文件夹 - how to copy a file to all desktop folders in the C: Users directory using powershell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM