Jump to content

Run PowerShell Get-RDUserSession PowerShell command and get back it's value?


DannyJ
 Share

Recommended Posts

If I try to run this script with   Get-ChildItem which means dir this script works perfectly, but If I try to run this command Get-RDUserSession, my script has the following error message:

Quote

Get-RDUserSession : The term 'Get-RDUserSession' is not recognized as the name of a cmdlet, function, script file, or o
perable program

This command runs perfectly in PowerShell admin and I get back the values

Get-RDUserSession -ConnectionBroker  broker.local | sort Username

Or you can try this command as well

Get-Command Get-RDUserSession

If I run the above mentioned command this runs perfectly in PowerShell but not with AutoIt.

Here is my script you can test the commands:

#include<array.au3>

$iPid = run('powershell Get-Command Get-RDUserSession'  , @WindowsDir , @SW_HIDE , 0x2)

;; This command not works in AutoIT you can test it in PowerShell but it won't work in Autoit

;$iPid = run('powershell Get-RDUserSession -ConnectionBroker  broker.local | sort Username'  , @WindowsDir , @SW_MAXIMIZE , 0x2) ; This command not works in AutoIT
;$iPid = run('powershell Get-ChildItem | sort Name'  , @WindowsDir , @SW_HIDE , 0x2) ; This runs perfectly
$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
 WEnd

;~ msgbox(0, '' , $sOutput)

$aOutput = stringsplit($sOutput , @LF , 2)
_ArrayDisplay($aOutput)

 

That could be the solution of the problem if I could run, directly this PowerShell command window and Write to it and save it's values.

Edited by DannyJ
Link to comment
Share on other sites

Get-Command : The term 'Get-RDUserSession' 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.

https://powershelladministrator.com/2015/12/01/get-logged-on-users-and-sessions/

Hope these help.
 

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...