Last active
March 21, 2017 22:45
-
-
Save NathanTheGr8/b57f8496d9957783124a05de8aa0ff2e to your computer and use it in GitHub Desktop.
returns the most frequent , recent user of this computer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get-freq-user | |
{ | |
$newest = 20 | |
$ComputerName = $env:computername | |
$UserProperty = @{ n = "User"; e = { ((New-Object System.Security.Principal.SecurityIdentifier $_.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])).ToString() } } | |
$logs = Get-EventLog System -Source Microsoft-Windows-Winlogon -ComputerName $ComputerName -newest $newest | select $UserProperty | |
$logs = $logs | Group-Object user | Sort Count | Select -First 1 | Select-Object -Property Name | Out-String | |
$index = $logs.indexOf("\") + 1 | |
return $logs.substring($index) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.reddit.com/r/PowerShell/comments/60pfga/get_most_frequent_user/