简体   繁体   中英

Use qwinsta in PowerShell ISE

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM