简体   繁体   English

Powershell远程计算机中的最后一个登录用户

[英]Powershell The last logon user in the remote computer

I want a script that collects all logons from the organization's computers, and shows the last user logon and the most user's access in the computer. 我想要一个脚本,该脚本从组织的计算机收集所有登录信息,并显示计算机上的最后一次用户登录和最多用户的访问权限。

I run this script from domain controller, but i only get the computer and the last logon, I don't have the last user logon or the frequency of logon. 我从域控制器运行此脚本,但是我只得到计算机和上次登录,没有上次用户登录或登录频率。

Get-ADComputer -Filter * -Properties * | FT Name, LastLogonDate, user -Autosize

You can search the security event logs on a machine to get its last login. 您可以在计算机上搜索安全事件日志以获取其最后的登录信息。

$startDate = (Get-Date) - (New-TimeSpan -Day 5)
$UserLoginTypes = 2,7
Get-WinEvent  -FilterHashtable @{Logname='Security';ID=4624;StartTime=$startDate}  | SELECT TimeCreated, @{N='Username'; E={$_.Properties[5].Value}}, @{N='LogonType'; E={$_.Properties[8].Value}} | WHERE {$UserLoginTypes -contains $_.LogonType}  | Sort-Object TimeCreated | SElect -last 1

That will search the last 7 days for interactive logins or unlocks on the computer and return the most recent one. 这将搜索最近7天的交互式登录信息或在计算机上解锁并返回最新的登录信息。

Update to get most logged in: 更新以获取最多的登录信息:

$startDate = (Get-Date) - (New-TimeSpan -Day 7)
$UserLoginTypes = 2,7
Get-WinEvent  -FilterHashtable @{Logname='Security';ID=4624;StartTime=$startDate}  | SELECT TimeCreated, @{N='Username'; E={$_.Properties[5].Value}}, @{N='LogonType'; E={$_.Properties[8].Value}} | WHERE {$UserLoginTypes -contains $_.LogonType}  | group UserName |  Sort-Object Count | Select -last 1

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

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