copy template vnc session and ssh tunnel, change linked tunnel in session and destination ip in tunnel

copy template vnc session and ssh tunnel, change linked tunnel in session and destination ip in tunnel

avatar

Hello,

I am currently trying to write a PowerShell script, and since my problem is quite specific, I decided to open a new topic.
The goal is to obtain a PowerShell script that is called with an IP address as a parameter.
With this new IP address, the script should clone a template for an SSH tunnel and a template for a VNC session.
In the tunnel, the new IP address becomes the destination IP address for the connection; in the VNC session, the new tunnel must be set up as the session connection.
After changing these values, the session should be started.


Changing the destination IP address in the tunnel has already been successfully achieved with the following lines.

$tunnel =Get-RDMSession -Name $tunnelname
$pf = $tunnel.Terminal.PortForwards[0]
$pf.Destination = $newIP
$tunnel.Terminal.PortForwards[0]=$pf
Set-RDMSession -Session $tunnel

I am currently struggling with the following issues:

  1. How do I copy a VNC session and an SSH tunnel while retaining all login information?
  2. How can I change the linked tunnel in the VNC session (Properties -> VPN\Tunnel\Gateway -> Settings -> Session)?
  3. How can I start the new session via PowerShell? (Or how do I get the “command line” from Properties -> Input Information to call it via cmd?


I have a workaround for the last question, as I can retrieve the session ID and data source ID from the objects and then use the cmd call but i would be rather happy with a direct powershell launch.
I used the search function but couldn't find any topics that resembled my questions.

Kind Regards
Felix


All Comments (5)

avatar

Hello Felix,

Thank you for reaching out to the Devolutions support team.

Everything that you mention could be done in RDM with a host entry.
You only have to set your tunnel as a child entry and use the variable $PARENT_HOST$.
By doing so, you can use all your templates on the same host.

For your questions regarding PowerShell:

  1. How do I copy a VNC session and an SSH tunnel while retaining all login information?
  • The $session = Get-RDMSession | Where-Object {$_.Name -eq "<entry name>"} could provide a lot of information if you call $session.VPN, for example.
  1. How can I change the linked tunnel in the VNC session (Properties -> VPN\Tunnel\Gateway -> Settings -> Session)?
  • use multiple variables $session1.vpn = $session2.VPN
  • Every change will not be applied if you do not do a Set-RDMSession $session1
  • The change will be applied to this PowerShel session
  1. How can I start the new session via PowerShell? (Or how do I get the “command line” from Properties -> Input Information to call it via cmd?
  • The Open-RDMSession cmdlet can open your session from your PowerShell session.


Best regards,

Patrick Ouimet

avatar

Hi Patrick
I managed to write a script which does all the what i needed.
just the open-rdmsession does not seem to work at all and i can't figure out why.

when executing the command with the id as paramter and verbose i get the following output and Nothing happens
Open-RDMSession -ID 61f525dc-2b3d-48db-885d-e35514448701
VERBOSE: [Open-RDMSession] Start
VERBOSE: [Open-RDMSession] Finish

the finish is immediate after the start

avatar

Hello Felix,

Thank you for this feedback.

Could you tell us which version of RDM you are using?
Which data source type are you using?
Additionally, which version of the module is currently installed?

Best regards,

Patrick Ouimet

avatar

Hi Patrick,

RDM Version 2025.2.30.0
local datasource
module version 2025.2.6

I made some research and found a Post which said that the launch of a session only works with the embedded powershell of rdm, is that correct?
or should open-rdmsession also work from an "external" Powershell?

thanks in advance

felix

avatar

Hello Felix,

Thank you for this feedback.

An RDM session should open in RDM with the cmdlet Open-RDMSession.
It is working inside and outside of RDM using PowerShell.

Which session exactly are you trying to open with this command?
Is it the SSH session or the tunnel?
Have you tried to open other sessions to see if this is related to session type or to your configuration?

Best regards,

Patrick Ouimet