Skip to content

Instantly share code, notes, and snippets.

@kmhuglen
Last active August 12, 2019 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmhuglen/b52d0afb59901dd0d7f1ab44d54442ee to your computer and use it in GitHub Desktop.
Save kmhuglen/b52d0afb59901dd0d7f1ab44d54442ee to your computer and use it in GitHub Desktop.
RDS: Find out who, when and from where users logon/logoff
$allRDPevents = Get-WinEvent -FilterHashtable @{Logname = "Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational" ; ID = 1149,1150,1148} -ErrorAction SilentlyContinue
$RDPevents = @()
foreach ($event in $allRDPevents)
{
$result = $null
switch ($event.ID)
{
1148 { $result = "failed" }
1149 { $result = "succeeded" }
1150 { $result = "merged" }
}
$RDPevents += New-Object -TypeName PSObject -Property @{
ComputerName = $env:computername
User = $event.Properties[0].Value
Domain = $event.Properties[1].Value
SourceNetworkAddress = [net.ipaddress]$Event.Properties[2].Value
TimeCreated = $event.TimeCreated
Result = $result
}
}
$RDPevents | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment