Hello. I am trying to build a .bat file for RDM to remotely access workstations using RDP shadow.
Right now, we use this script, it interacts with us and asks for computer name and then for session number:

@echo off
set /P rcomp="Enter name or IP of a Remote PC: "
query session /server:%rcomp%
set /P rid="Enter RDP user ID: "
start mstsc /shadow:%rid% /v:%rcomp% /control /noConsentPrompt


How can i send a variable into this script, e.g. $COMPUTERNAME instead of %rcomp% after i right-click onto workstation and select macros/script/tools?

Thank you!

Clock3 mths

Hello,

Sorry for the long delay, i tested several possibilities for this one, as i wanted to do it through your .bat file.

I have been able to achieve this with a PowerShell (Local) Macro/Script/Tool.
Create a new entry, in Macro/Script/Tool, PowerShell (Local), select Embedded Script, Click on Edit embedded Script.
In the dialog box, I entered this script :

$SessionID = Read-Host "Enter RDP user ID:"
mstsc /v:$HOST$ /shadow:$SessionID /control /noConsentPrompt



This script will still prompt you for the ID of the connection, through a PowerShell imput (that will look quite the same as what you are already doing)

Then, from a session, the $HOST$ will do the trick.

I hope this helps.

Regards,



Alex Belisle

signaturesignature

Clock3 mths

Thank you for a reply.
I would like to have the ability to see user sessions in case, multiple users are logged on to computer. query session /server:%rcomp% did it before. However, powershell does not seem to have such command.

Clock3 mths

Hello,

It turns out that you can run query.exe from a powershell window. simply add the command before the rest like:


query.exe session /server:$HOST$
$SessionID = Read-Host "Session ID"
mstsc /v:$HOST$ /shadow:$SessionID /control /noConsentPrompt


Make sure that the "Run in 64-bits Mode" is checked from the Advanced Tab.


Best regards,



Alex Belisle

signaturesignature

Clock2 mths

It worked! Thank you very much!

Clock2 mths