0

I would request some help on finding a user on a terminal session (like Citrix). I've gone through most of the questions asked on "Terminal Session" on this forum. Unfortunately, nothing really helped me :(

I tried searching for get-PSterminalsessions (http://psterminalservices.codeplex.com) but this module is not loading after I follow the steps as given. I'm tried it on Win 7 and as well as on 2008 R2.

When I try using invoke-expressions -command "Quser xyz" it does not return anything.

3
  • When you do Import-Module PSTerminalServices, what error do you get?
    – jscott
    Jan 7, 2012 at 20:57
  • I get this error " Import-Module : The specified module 'PSTerminalServices' was not loaded because no valid module file was found in any module directory."
    – Phanindran
    Jan 11, 2012 at 13:00
  • But I see them in the Module folders, on my profile and programfiles.
    – Phanindran
    Jan 11, 2012 at 13:01

1 Answer 1

2

try this from the powershellcommunity.org script repository:

Function Get-ComputerSession {
<#  
.SYNOPSIS  
    Retrieves all user sessions from local or remote server/s
.DESCRIPTION
    Retrieves all user sessions from local or remote server/s. Requires query.exe in order to run properly.
.PARAMETER computer
    Name of computer/s to run session query against.              
.NOTES  
    Name: Get-ComputerSession
    Author: Boe Prox
    DateCreated: 01Nov2010 

.LINK  
    https://boeprox.wordpress.org
.EXAMPLE
Get-ComputerSessions -computer "server1"

Description
-----------
This command will query all current user sessions on 'server1'.    

#> 
[cmdletbinding(
    DefaultParameterSetName = 'session',
    ConfirmImpact = 'low'
)]
    Param(
        [Parameter(
            Mandatory = $True,
            Position = 0,
            ValueFromPipeline = $True)]
            [string[]]$computer
        )             
Begin {
    $report = @()
    }
Process { 
    ForEach($c in $computer) {
        # Parse 'query session' and store in $sessions: 
        $sessions = query session /server:$c
            1..($sessions.count -1) | % {
                $temp = "" | Select Computer,SessionName, Username, Id, State, Type, Device
                $temp.Computer = $c
                $temp.SessionName = $sessions[$_].Substring(1,18).Trim()
                $temp.Username = $sessions[$_].Substring(19,20).Trim()
                $temp.Id = $sessions[$_].Substring(39,9).Trim()
                $temp.State = $sessions[$_].Substring(48,8).Trim()
                $temp.Type = $sessions[$_].Substring(56,12).Trim()
                $temp.Device = $sessions[$_].Substring(68).Trim()
                $report += $temp
            } 
        }            
    }
End {            
    $report
    }
}
1
  • Thanks for the script. I shall check this and update you in a day or so.
    – Phanindran
    Jan 11, 2012 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .