Search code examples
powershellpowershell-2.0rdpmstsc

How to find amount of time mstsc is used and by whom?


Our team has geographically dispersed and many virtual machine will be connected by them using remote desktop. I would like to find who is accessing a remote desktop session and how long it is being used.

I tried to do it with powershell. I wrote a script where user will invoke mstsc using powershell. It will log who has logged in and when he logged. But i would like to find when some one log off from mstsc or disconnect mstsc . Is there any way to capture that information in log file using powershell. Whether any event will be triggered while closing mstsc which could be used for it?


Solution

  • I wrote a PowerShell module,PSTerminalServices (http://psterminalservices.codeplex.com), that is built on Cassia. Here's a sample command output:

    PS> Get-TSSession | fl *
    
    IPAddress          :
    State              : Active
    ApplicationName    :
    Local              : False
    RemoteEndPoint     :
    InitialProgram     :
    WorkingDirectory   :
    ClientProtocolType : Console
    ClientProductId    : 0
    ClientHardwareId   : 0
    ClientDirectory    :
    ClientDisplay      : Cassia.Impl.ClientDisplay
    ClientBuildNumber  : 0
    Server             : Cassia.Impl.TerminalServer
    ClientIPAddress    :
    WindowStationName  : Console
    DomainName         : homelab
    UserAccount        : homelab\shay
    ClientName         :
    ConnectionState    : Active
    ConnectTime        : 12/15/2011 2:47:02 PM
    CurrentTime        : 12/23/2011 4:35:21 PM
    DisconnectTime     :
    LastInputTime      :
    LoginTime          : 12/15/2011 3:11:58 PM
    IdleTime           : 00:00:00
    SessionId          : 1
    UserName           : shay