1

I am trying to use qwinsta and rwinsta with powershell code. When I try to run this I get an error "The term 'qwinsta' is not recognized as the name of a cmdlet, function, script file, or operable program." I need to be able to do this remotely on several machines without having to add any .dll's or modules to the other machines. I tried the Terminal Services Powershell Module, but you need to be able to put that on the remote machines and I am not able to do that.

Within powershell ISE how would I run qwinsta? I am not looking to parse the information just gather it. This is the following code I have tried (which I had found on this site also):

function Get-TSSessions {
    param(
        $ComputerName = "localhost"
    )

    qwinsta /server:$ComputerName |
    #Parse output
    ForEach-Object {
        $_.Trim() -replace "\s+",","
    } |
    #Convert to objects
    ConvertFrom-Csv
}
Get-TSSessions -ComputerName "localhost" | ft -AutoSize
sk1919
  • 11
  • 2
  • 6
  • Can't you use use the full path? It's not like it should ever be somewhere other than `C:\Windows\System32\qwinsta.exe`. – Bacon Bits Apr 29 '15 at 15:41
  • Command `qwinsta` is an alias for `query session`. – Bill_Stewart Apr 29 '15 at 15:46
  • 1
    possible duplicate of [Split text by columns in PowerShell](http://stackoverflow.com/questions/29125337/split-text-by-columns-in-powershell) – Bill_Stewart Apr 29 '15 at 15:48
  • I looked at this issue but when I try to run it i still get the same error message. Its not recognized. – sk1919 Apr 29 '15 at 16:41
  • What is your PowerShell version? Can you verify the path it is located? Are you running x64 ISE or 32bit. That might be a factor – Matt Apr 29 '15 at 19:29

1 Answers1

1

Best I have is that you are running PowerShell ISE (x86). When I run the command qwinsta from there I get the same error as you. This is of course assuming you have a 64-bit OS.

The term 'qwinsta' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

Check your PowerShell ISE architecture. It's right in the title bar. In that regard one thing you could do is run the "PoweShell ISE" and not "PowerShell ISE (x86)". Checking into the reason this is the case. qwinsta must not be available to the 32 bit shell.

Since qwinsta.exe is located in C:\windows\system32 that location relative to ISE x86 would be C:\Windows\SysWOW64 which does not contain that executable. Note: this reasoning is speculation and the logic could be flawed.

Parsing QWINSTA

Have a good look at the answers here for parsing qwinsta: Split text by columns in PowerShell

FYI one of them is mine.

Community
  • 1
  • 1
Matt
  • 45,022
  • 8
  • 78
  • 119
  • Hi Matt, maybe I am not understanding, sort of new to powershell myself....I am running PowerShell ISE (x86), my version is 3.0. I am not sure what you mean by checking the ISE Architecture. I did take a look at the Split text by columns in Powershell and my issue is not parsing the data just trying to get the data. I am not even able to get it. – sk1919 Apr 29 '15 at 20:10
  • @sk1919 There are other solutions but I was suggesting that you run the 64-bit shell and tell me what happens (without the x86 on it). Updated the answer as well to be clearer. I agree that split is not your issue. Switch which ISE you are running is what Im trying to tell you – Matt Apr 29 '15 at 20:37
  • Ok, thanks @Matt - I tried that and it seem to work. Much appreciate the help! – sk1919 Apr 29 '15 at 21:20