
In order to get the Remote Desktop Client to function in a .NET project you must obtain the Remote Desktop ActiveX control wrapper (MSTSCLib.dll and AxMSTSCLib.dll).
MSTSCLib
You may need to unblock the files, since they were downloaded from internet.
File –> Right click –> Properties

Create PowerShell Winform and add Panel control. Additionally add buttons for connect, disconnect, refresh, etc.
Load into your PowerShell script both ActiveX component assemblies:
1 2 |
[system.reflection.Assembly]::LoadFrom("$dllpath\AxInterop.MSTSCLib.dll") [system.reflection.Assembly]::LoadFrom("$dllpath\MSTSCLib.dll") |
where $dllpath is the location of the files.
Create new Object type and add it to the form Panel control:
1 2 3 |
$rdp = New-Object AxMSTSCLib.AxMsRdpClient4NotSafeForScripting $rdp.Dock = 'Fill' $RDPPanel.Controls.Add($rdp) |
Create new on-click event for button “Connect” and fill in the RDP client properties:
1 2 3 4 5 6 7 8 9 10 11 12 |
$rdp.Name = "MyPowerShellRDP" $rdp.Enabled = "true" $rdp.AdvancedSettings2.DisplayConnectionBar = 'true' $rdp.AdvancedSettings2.EnableCredSspSupport = "true" $rdp.ConnectingText = 'Connecting...' $rdp.DisconnectedText = "Disconnected" $groupboxSettings.Enabled = $false $rdp.Server = $textboxServerName.Text $rdp.UserName = $textboxUsername.Text $rdp.AdvancedSettings2.RDPPort = $textboxRDPPort.Text $rdp.AdvancedSettings2.ClearTextPassword = $textboxPassword.Text $rdp.Connect() |
Click here for the Microsoft Remote Desktop ActiveX control client settings reference.