Skip to content

Instantly share code, notes, and snippets.

@awakecoding
Created September 7, 2022 01:20
Show Gist options
  • Star 75 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save awakecoding/5fda938a5fd2d29ebffb31eb023fe51c to your computer and use it in GitHub Desktop.
Save awakecoding/5fda938a5fd2d29ebffb31eb023fe51c to your computer and use it in GitHub Desktop.
function Get-RdpLogonEvent
{
[CmdletBinding()]
param(
[Int32] $Last = 10
)
$RdpInteractiveLogons = Get-WinEvent -FilterHashtable @{
LogName='Security'
ProviderName='Microsoft-Windows-Security-Auditing'
ID='4624'
LogonType='10' # RemoteInteractive
} | Select-Object -First $Last
$RdpNetworkLogons = @()
foreach ($RdpInteractiveLogon in $RdpInteractiveLogons) {
$RdpNetworkLogon = Get-WinEvent -FilterHashtable @{
LogName='Security'
ProviderName='Microsoft-Windows-Security-Auditing'
ID='4624'
LogonType='3' # Network
} | Where-Object {
($_.TimeCreated -lt $RdpInteractiveLogon.TimeCreated) -and
($_.Properties[5].Value -eq $RdpInteractiveLogon.Properties[5].Value)
} | Select-Object -First 1
$RdpNetworkLogons += $RdpNetworkLogon
}
$RdpNetworkLogons | ForEach-Object {
[PSCustomObject] @{
EventTime = $_.TimeCreated
UserName = $_.Properties[5].Value
DomainName = $_.Properties[6].Value
AuthPackage = $_.Properties[10].Value
SourceAddress = $_.Properties[18].Value
}
}
}
# Get-RdpLogonEvent -Last 10 | Format-Table
@madeonukraine
Copy link

can you teach how to use it? maybe some video on YouTube, you have many interesting scripts but if i start
PS C:\Users\MyMainPC\Downloads\downgrade> .\Get-RdpLogonEvent.ps1 .\Security.evtx
that do nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment