Created
April 11, 2021 19:11
-
-
Save mertcangokgoz/ed9a81b54f5eeb710bb0ae38d68bbdde to your computer and use it in GitHub Desktop.
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
Get-EventLog -LogName Security -after (Get-date -hour 0 -minute 0 -second 0) | Where-Object { (4624, 4778) -contains $_.EventID -and $_.Message -match 'logon type:\s+(10)\s' } | % { | |
(new-object -Type PSObject -Property @{ | |
TimeGenerated = $_.TimeGenerated | |
ClientIP = $_.Message -replace '(?smi).*Source Network Address:\s+([^\s]+)\s+.*', '$1' | |
UserName = $_.Message -replace '(?smi).*Account Name:\s+([^\s]+)\s+.*', '$1' | |
UserDomain = $_.Message -replace '(?smi).*Account Domain:\s+([^\s]+)\s+.*', '$1' | |
LogonType = $_.Message -replace '(?smi).*Logon Type:\s+([^\s]+)\s+.*', '$1' | |
}) | |
} | Sort-Object TimeGenerated -Descending | Select-Object TimeGenerated, ClientIP ` | |
, @{N = 'Username'; E = { '{0}\{1}' -f $_.UserDomain, $_.UserName } } ` | |
, @{N = 'LogType'; E = { | |
switch ($_.LogonType) { | |
2 { 'Interactive - local logon' } | |
3 { 'Network connection to shared folder)' } | |
4 { 'Batch' } | |
5 { 'Service' } | |
7 { 'Unlock (after screensaver)' } | |
8 { 'NetworkCleartext' } | |
9 { 'NewCredentials (local impersonation process under existing connection)' } | |
10 { 'RDP' } | |
11 { 'CachedInteractive' } | |
default { "LogType Not Recognised: $($_.LogonType)" } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment