Forum / Remote Desktop Manager - SDK

PowerShell like command for external C# application

  • Create an Issue
  • Cancel

Hi,

I already use the PowerShell extension from you to open a session in RDM. Using Get-RDMSession and Open-RDMSession is really a fun and improve my work.

We also use a small tool to get quick information about user, clients and server, that also allow us to do some actions on those. I would really like to use the functionality of the PowerShell to connect to a server. I know there are command line arguments or even a web protocol handler but all of this require the session id of the server. I don't want to use a quick connect to a fqdn because then I loose the settings of the session, like authentication and so on.

I could try to create a PowerShell env within my code and add the snap-in but that would require that every of my co-worker has registered the snap-in. Another way is to read the information directly from the database.

I already have tried to add the RemoteDesktopManager.Core.dll as a reference but that also look too much. I hope you can help me with my Problem.

Thanks for your time!

Regards,
Philip

Clock5 yrs

Hello,

The powershell snap-in is registered as part of having installed RDM, theoretically you could connect through Remote Powershell on a machine that has RDM. I havent tested it myself but I could give it a go tomorrow.

For RDP connections, not having RDM on the local machine, you will need to generate a RDP file and you will hit the issue that RDP itself doesnt allow to save credentials.

For other technologies it will depend on their capabilities and the tools you have locally,

Best regards,



Maurice Côté

signaturesignature

Clock5 yrs

Hi Maurice,
thank you for your quick answer but it looks I was not clear enough.

My tool is only running on machines where RDM is installed. But I need to correct you, the powershell snap-in is not registered as a part of RDM. You need to manually register the assembly or start the powershell from within RDM. But are my co-workers not a PowerShell nerd like me so i can't rely that they will update the registration. Additional there is always the problem that if you don't unregistered the assembly before you update RDM then you need to clean the registry for the old Snap-In to get it working probably.

I have attached a image of the tool we are using in our office. At the moment I can search for a user and get all needed information to give remote support. I'm on the way to extend this tool to include clients and server as well. In case it's a server i would like to add a button so i can start a new session within RDM like a remote call.

So my request is to do the following within a C# code:

  • get the session id by query RDM with the hostname
  • request RDM to start a new session with the session id i just receive.

Is there an easy way to archive this?


Best regards,
Philip

Capture.PNG
Clock5 yrs

Hello,

Registering the snapin, pointing to another version, etc, would be handled by a simple powershell script that you write once per version, I have that automated on my machine and I could share that in the powershell forums. The "registered" part I was mentioning was in the registry and the fact that we are bound to a specific version at this time. We will convert our library to a module in the future.

The primary question is using c# though. The SDK would allow you to create new entry types, but not what you would need to control RDM like you want.

If you ask for a solution that would work with the technologies we have right now, it would be a powershell script to get the session Id of the appropriate session, then calling RDM with a command line to open that session. I can provide guidance on creating a the "load" part of the powershell script.

Best regards



Maurice Côté

signaturesignature

Clock5 yrs

Thanks for your help. The problem is, a no PowerShell user will not take care to run that script before or after an update. If you could provide me with that script would be nice and for the time being I can life with that. Looking forward to see a proper module from you! And I hope you will extend the possibilities of the commands like piping or directly search for a session instead of getting all.

Even better would be the option to do it directly from C#, let's see what the future will bring.

I have created a new class to handle my request. Maybe somebody else can use it as well:

public class RDMSession
{
public string id { get; set; }
public string dataSourceId { get; set; }
public string name { get; set; }

public static List<RDMSession> ReceiveSessionList()
{
PowerShell ps = PowerShell.Create();
ps.AddScript("Add-PSSnapin -Name Remote.Desktop.Manager*; Get-RDMSession");

List<RDMSession> result = new List<RDMSession>();
foreach (PSObject item in ps.Invoke())
{
RDMSession session = new RDMSession();
session.id = item.Properties["id"].Value.ToString();
session.dataSourceId = item.Properties["dataSourceid"].Value.ToString();
session.name = item.Properties["name"].Value.ToString();
result.Add(session);
}

ps.Dispose();
return result;
}

public static RDMSession findFromSessionListByName(List<RDMSession> sessionList, string name)
{
return sessionList.Find(o => o.name == name);
}
}

Thank you!

Best regards,
Philip

Clock5 yrs