Script to copy string from "gatewayaccesstoken" and paste to RDP Connection settings
Hello,
Would it be possible to have a script that would copy the string from "gatewayaccesstoken" from a saved .RDP file and paste that string in the RDP - Connection - Gateway access token before launching the RDP session?
Copy from:
Paste to:
What would be the best way to accomplish this?
Thanks,
SP
Hi SP,
You could use something like this, note this would be run before connecting via Tools > PowerShell (RDM CmdLet)
$rdp = (get-content "C:\Path\to\file.rdp") -like 'gatewayaccesstoken*' -split 'gatewayaccesstoken:s:' | Select-Object -Skip 1 $session = Get-RDMsession -Name 'yoursessionname' $session.RDP.GatewayAccessToken = $rdp Set-RDMSession $session Update-RDMUI
You could also try something like this on the entry itself under Properties > Events> Before Open > PowerShell
$rdp = (get-content "C:\Path\to\file.rdp") -like 'gatewayaccesstoken*' -split 'gatewayaccesstoken:s:' | Select-Object -Skip 1 $RDM.Connection.RDP.GatewayAccessToken = $rdp
This would need to be tested though. You could also point the event to a created Macro for this (note that copy/pasting will result in an error.)
Best regards,
Eric St-Martin
Hi Eric,
Thanks for the info. Unfortunately, I don't see Tools > PowerShell (RDM CmdLet). Is this only available in the Enterprise version? The version I'm testing with is RDM Free 2021.1.41.0.
Thanks,
SP
Hi SP,
Ahh that module is only available in Enterprise editions.
In your case, you could use the following on the sessions Events under Properties > Events> Before Open > PowerShell .
$rdp = (get-content "C:\Path\to\file.rdp") -like 'gatewayaccesstoken*' -split 'gatewayaccesstoken:s:' | Select-Object -Skip 1
$RDM.Connection.RDP.GatewayAccessToken = $rdp
Please let me know if this works for you.
Best regards,
Eric St-Martin
Hi Eric,
Yes, this works!
Thanks for your help,
SP
Hi SP,
My pleasure! Glad to hear it's working.
Best regards,
Eric St-Martin
As a very late addition, I needed this same flow, since the auth service I use downloads an RDP file each time I connect, and the token in the file downloaded is only good for 30 minutes. I found it easier to automatically select the most current file, and delete anything older than a day. In case its useful for someone else:
$path = "C:\Users\myusername\Downloads"
$rdpfilepat = "myusername@mydomain.com-boxname*.rdp"
$rdpfile = (gci "$path\$rdpfilepat" | sort LastWriteTime | select -last 1)
$token = (get-content "$rdpfile") -like 'gatewayaccesstoken*' -split 'gatewayaccesstoken:s:' | Select-Object -Skip 1
$RDM.Connection.RDP.GatewayAccessToken = $token
Get-ChildItem "$path" -Recurse -File | Where-Object {($_.Name -like "$rdpfilepat") -and $_.CreationTime -lt (Get-Date).AddDays(-1)} | Remove-Item -Force
All that went under Events > Before Open > PowerShell.
I was amazed to find out I could do this - you guys have an outstanding tool here.
Cheers,
Geoff
Hello,
Thank you for the feedback! Let us know if you have any further questions!
Best regards,
Etienne Lord