如何使用powershell检测用户是否从windows系统(最好是win7、vista或XP)登录或注销?
我想注册每次登录和注销机器的日期和时间。
先感谢您
您可以从事件日志中获取此信息:
Get-EventLog System -Source Microsoft-Windows-Winlogon
登录的 InstanceId 为 7001,注销的 InstanceId 为 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 从远程计算机获取这些事件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)