It is possible to execute a PowerShell script before establishing a connection, cancel the launching or even import external PowerShell scripts. To accomplish this you would need to go into the Properties of the entry under Events – Before Open – PowerShell.
Using the $RDM.connection property, the script temporarily changes any of the session properties in the context of the session launch only. When the session is closed, the properties revert back to their original values.
Here are some example of scripts that can be executed.
In the PowerShell script window, copy the script provided below and click OK.
$date = Get-Date -DisplayHint Date
$RDM.Connection.TabTitle = $RDM.Connection.Name + "(" + $date + ")"
To cancel the launch of a session, in the PowerShell script window of the entry, copy the script below and click OK to save.
$RDM.Cancel = $true
The Import-Module cmdlet can be used to call an external PowerShell script.
In the following sample, it loads the RSAToken.ps1 script and call its function New_RSAToken that returns a value. Then it appends the content of the $RSAToken variable to the session's password before opening the RDP session.