Skip to content

Instantly share code, notes, and snippets.

@ffcommax
Created November 29, 2021 18:17
Show Gist options
  • Save ffcommax/a1ccb72af36631bcea751e95ee4710ac to your computer and use it in GitHub Desktop.
Save ffcommax/a1ccb72af36631bcea751e95ee4710ac to your computer and use it in GitHub Desktop.
rdphistory
$LogName = 'Microsoft-Windows-TerminalServices-LocalSessionManager/Operational'
$Results = @()
$Events = Get-WinEvent -LogName $LogName
foreach ($Event in $Events) {
$EventXml = [xml]$Event.ToXML()
$ResultHash = @{
Time = $Event.TimeCreated.ToString()
'Event ID' = $Event.Id
'Desc' = ($Event.Message -split "`n")[0]
Username = $EventXml.Event.UserData.EventXML.User
'Source IP' = $EventXml.Event.UserData.EventXML.Address
'Details' = $Event.Message
}
$Results += (New-Object PSObject -Property $ResultHash)
}
$Results | Export-Csv 'Remote Desktop Users.csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment