Created
July 31, 2018 18:29
-
-
Save robderickson/7ce75e07f65bac4dcbb5dd9c01e09ec9 to your computer and use it in GitHub Desktop.
Get failed logon events 4771 and 4776, and return the TargetUserName and Workstation or IPAddress values recorded in the events.
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
[CmdletBinding()] | |
param( | |
[string[]]$ComputerName, | |
[string]$SamAccountName | |
) | |
PROCESS { | |
foreach ($computer in $ComputerName) { | |
$events = Get-WinEvent -ComputerName $computer -LogName Security -FilterXPath "*[System[(EventID='4771' or EventID='4776')]][EventData[Data='$SamAccountName']]" | |
foreach ($event in $events) { | |
$UserName = ([xml]$event.ToXml()).Event.EventData.Data.Where{$_.Name -eq 'TargetUserName'}.InnerText | |
if ($event.id -eq '4771') { | |
$LogonSource = ([xml]$event.ToXml()).Event.EventData.Data.Where{$_.Name -eq 'IPAddress'}.InnerText | |
} elseif ($event.id -eq '4776') { | |
$LogonSource = ([xml]$event.ToXml()).Event.EventData.Data.Where{$_.Name -eq 'Workstation'}.InnerText | |
} | |
[PSCustomObject]@{ | |
Username = $UserName | |
LogonSource = $LogonSource | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment