如何检测用户是否已经使用powershell从windows系统(最好是win7、vista或XP)登录或注销?
我想注册每次登录和注销机器的日期和时间。
提前谢谢你
发布于 2011-03-04 04:29:32
您可以从事件日志中获取以下信息:
Get-EventLog System -Source Microsoft-Windows-Winlogon登录的InstanceId为7001,注销的为7002。用户帐户是ReplacementStrings中的SID。
这里有一些对你更有用的代码。
$UserProperty = @{n="User";e={(New-Object System.Security.Principal.SecurityIdentifier $_.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])}}
$TypeProperty = @{n="Action";e={if($_.EventID -eq 7001) {"Logon"} else {"Logoff"}}}
$TimeProeprty = @{n="Time";e={$_.TimeGenerated}}
Get-EventLog System -Source Microsoft-Windows-Winlogon | select $UserProperty,$TypeProperty,$TimeProeprty您还可以通过将"-ComputerName“参数添加到Get-EventLog来从远程计算机获取这些事件。
发布于 2011-03-03 03:13:38
这样的事情已经存在于windows系统日志中,类型为"Winlogon“。我不知道如何通过powershell从那里提取信息,但至少日志记录部分已经为您准备好了。
https://stackoverflow.com/questions/5172111
复制相似问题