Implemented

Remote Powershell Script

avatar

RDM: 2022.3.16.0

Hi All

Im trying to run a Powershell Script from RDM on a remote Machine with specified Credentials via VPN.

So i created a new Entry of Type "Session > Powershell".
Under "Host and Credentials" i specified the remote Server FQDN on which the Script should be runned and under Credentials i specified the Credential Object which is located on the same Vault:
forum image

In General i selected "Embedded Script" and added the following Code for Testing:

Write-Host $env:computername
Write-Host $env:username


When i run the Script by Doubleclick the Session Object, it opens a local Powershell Console which returns my own Computername and the specified correct Username from the Credentials Object.

What do i wrong that the Script is not running on the remote Machine?
The Goal is to run a Script on the specified Host with the linked Credentials.

Thanks,
Andreas

Edit: When i try to select the specific Host under "Host" (above Credentials), the List is empty. Thats why i chosed the Field "Host" under "Host and Credentials"

All Comments (10)

avatar

Hello Andreas,

I can reproduce this behaviour. I will verify with our engineering team to know if there is anything we can do to fix this problem.

In the meantime, I presume the PowerShell Remote Console entry type is working properly in your environment? This will only open a remote console without being able to execute any script.

forum image

Best regards,

Érica Poirier

avatar

Hello Andreas,

So the possibility to set a host and credentials in the PowerShell session entry is to be able to use the information within the script by using the corresponding variables.

forum image

Would it be a good solution to add the Embedded script section in the PowerShell Remote Console entry type?

Best regards,

Érica Poirier

avatar

Hi Erica

Thanks for the Informations.

Would it be a good solution to add the Embedded script section in the PowerShell Remote Console entry type?


Yes, i need an Option to send a Script via this Type. Would be great to have this added!

In Future i want to run a Script before a Connection is opening. So it would be nice, if the Script Section also could be added on "Macro/Script/Tool" Section:
forum image

But on this Type im also missing the "Host" and "Credentials" Section.

With this Type im able to start the specific Script before open a Session via Events:
forum image

Best Regards,
Andreas

avatar

Hi Andreas,

Thank you for your feedback.

I have submitted an improvement ticket to our engineering team to add the embedded script property in the PowerShell Remote Console entry. Once an update will be available, we will post it here.

About the PowerShell (Remote) Macro/Script/Tool entry type, as it's intended to run against an existing entry like any other remote tools, that's the reason why the Host and Credential section are not available.

About running a script before opening a session, is the Playlist feature would be an appropriate workaround?

Best regards,

Érica Poirier

avatar

Thank you Erica, the Playlist Feature looks quite interessting!
But on every case, i need to have an Option to send a Script trough Remote Powershell Session.

Will looking forward for this Option 😊

Best Regards,
Andreas

avatar

Hi Erica

Is there any News about this Problem?
Or is there maybe an option to use this Feature maybe available by using the Remote Agent on the Destination VM?

I want to achieve this:

  1. User clicks on a Session Object to connect
  2. Before the Session opens, RDM should now automatically launch a predefined Script on a third Machine
  3. User Works on the Server

...
On Disconnection:

  1. User Disconnects
  2. RDM automatically launch another predefined Script on the third Machine


Thanks for any Inputs!

Best Regards,
Andreas

avatar

Hello Andreas,

Thank you for your feedback.

The improvement to add the embedded script property in the PowerShell Remote Console entry is still in the backlog. I will ask our engineering team if they can increase the priority of this ticket.

For what you want to achieve, It is possible to use the Before Open and After Close events in the RDP entry set with PowerShell. In that sample, I use the folder variable $COMPUTER_HOST$ that refers to the parent folder's host name.

forum image

forum image

Let me know if that could be a good solution.

Best regards,

Érica Poirier

avatar

Hi Erica

Thanks for this Example!

Whats the Type of your Example?
Im not able to select "Server" at the bottom left corner. It only shows the already selected Type.

Is this also possible to run the Script as different users (in example by selecting specific Credentials from Vault)?

I tried it right now with 2 Powershell Scripts by using invoke Command (thats the only way i got it running on the remote server). Both Scripts working when running it directly.
forum image

But im not able to select those Scripts on Events. The List is empty:
forum image
forum image

Did i made some missunderstandings?

And when i try to use the Scripts with the Server Connection in a List, it doesnt wait for the Powershell Exit. It just opens the script, opens the connection and directly opens the second script.
But it should start the first script, wait until it closes, then opening the server. And after Disconnect it should run the second Script; or at least an option to specify the run option (serial or parallel) option.

Best Regards,
Andreas

avatar

Hello Andreas,

Thank you for your feedback.

The type I'm using in my sample is a Folder.

No it's not possible to run the script as another in the Event section.

The reason why you cannot select the scripts you have created it's because they are PowerShell session entry. To be able to select them, you need to create a PowerShell (Local) Macro/Script/Tool en try type (green icon).

forum image

Regarding the script to run before starting the session and the one after closing the session, this will be possible in the Event section. We already have a ticket opened internally to run a script remotely on the machine through the agent as at the moment it's not possible in the Event section.

I'm not sure if it's possible to add a parameter for the Play list to wait for the scripts to be completed before launching the session. I will verify with the engineering team.

Best regards,

Érica Poirier

avatar

Hello,

We've added the possibility to input an Embedded Script in the PowerShell Remote Console entry. You'll find the Edit Embedded Script link text available in the Advanced section of said entry. This should accessible with 2023.1

Regards,

Jafran Majeau