PowerShell Script to Export RDP Session Logs to CSV

Prakash Modak 111 Reputation points
2023-07-24T14:46:19.9966667+00:00

Is it possible to obtain logs of RDP sessions? I want to generate a report on the logon, logoff, and the total session time for specific users. I went through this link (https://frsecure.com/blog/rdp-connection-event-logs/) to get the event IDs for logon, logoff, session disconnect, and connect event IDs. Can someone guide me in creating a PowerShell script that will export these logs to a CSV file?

The following is a table outlining the necessary event IDs to harvest: LOG ON:

Security 4624, 4625
TerminalServices-RemoteConnectionManager/Operational 1149
RemoteDesktopServices-RDPCoreTS /Operational 98, 131
TerminalServices-LocalSessionManager/Operational 21, 22, 25
LOG OFF:
Security 4634, 4647
TerminalServices-LocalSessionManager/Operational 23, 40
Windows for business Windows Client for IT Pros User experience Remote desktop services and terminal services
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-07-26T08:58:16.5266667+00:00

    Hello @ Prakash Modak 

    You can use the Get-WinEvent cmdlet to export specific event IDs from the Windows event logs. Then using the Export-Csv to export the results to a CSV file.

    powershell - Export Specific Windows Security Event Logs - Stack Overflow

    Get-WinEvent (Microsoft.PowerShell.Diagnostics) - PowerShell | Microsoft Learn

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.