Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ( 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.

share|improve this question
When you do Import-Module PSTerminalServices, what error do you get? – jscott Jan 7 '12 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 '12 at 13:00
But I see them in the Module folders, on my profile and programfiles. – Phanindran Jan 11 '12 at 13:01

try this from the script repository:

Function Get-ComputerSession {
    Retrieves all user sessions from local or remote server/s
    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.              
    Name: Get-ComputerSession
    Author: Boe Prox
    DateCreated: 01Nov2010 

Get-ComputerSessions -computer "server1"

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

    DefaultParameterSetName = 'session',
    ConfirmImpact = 'low'
            Mandatory = $True,
            Position = 0,
            ValueFromPipeline = $True)]
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 {            
share|improve this answer
Thanks for the script. I shall check this and update you in a day or so. – Phanindran Jan 11 '12 at 13:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.