Forum / Remote Desktop Manager - PowerShell Repository

Powershell remote sessions in RDM

  • Create an Issue
  • Cancel

Good day,

I am using v14 of remote desktop manager.

I would like to run simple (Get-WmiObject Win32_logicaldisk) command on a server to check state of disk drives on server, is it possible to use PS RDM module to acomplish this?

I would prefer to open a session using admin credentials to server and then get the information. I saw an example of similar feature with an earlier version.


If such thing is possible, would you mind posting an example.

Clock4 mths

Hello,

You can create a PowerShell (Remote) Macro/Script/Tool entry type and then run it on the server you want to get the information.

Here are some methods to run the script.

The first one is to execute it using the RDM Agent. It is mandatory that the RDM Agent must be installed on the remote computer. And a connection must already be opened to this machine. Then you run the script using the Execute script via Agent feature.

image

Another method is to run the script from the Macros/Scripts/Tools panel. The remote computer must be available from your workstation to be able to run the script. And no need to have an open connection to that remote machine.

image

Best regards,



Érica Poirier

signaturesignature

Clock4 mths

Thank you for suggestion, but these involve using a GUi to setup every single sever.

I have a very large amount of machines and i am not sure that i want to go one by one on each and do the clicks, then copy data i get and create report by hand.

The whole idea would i would like to go trough a select list of machines and capture the returned values in a variable that i can later use to construct a report automaticaly.

I see that you have "New-RDMSession -Type PowerShell/PowerShellRemoteConsole" commands, is there a way i coudl use those with specific credentials to achieve this ?

At the moment i am failing to open a powershell session, an example on how to do this would be great.

Clock4 mths

Hello,

It is possible to run a script that will connect on a set of remote machines that are existing in RDM to get the information.

You need to use the Get-RDMSession cmdlet to retrieve the list of the remote computers from RDM. Then, using this list, you can get the information remotely using the Get-WmiObject cmdlet. To connect on those remote using specific credentials available in RDM, you can use the Get-RDMSessionUsername and Get-RDMSessionPassword cmdlets.

Here is a sample script that could be use to get the list of the computers you want to connect to from RDM and get the main credential.You may have to adapt it to fit your environment.

* Get all RDP entries from RDM

$computers = Get-RDMSession | where {$_.ConnectionType -eq "RDPConfigured"}

* Get the main credential to connect on those machines
$credsession = Get-RDMSession -Name "MyAdminCredential"
$username = Get-RDMSessionUserName -Session $credsession
$passwd = Get-RDMSessionPassword -Session $credsession
$credential = New-Object System.Management.Automation.PSCredential($username, $passwd)

Here is a page that contains an example on how to use the Get-WMIObject cmdlet to get the information from a remote computer using specific credentials.
https://blogs.technet.microsoft.com/gary/2009/07/23/creating-a-ps-credential-from-a-clear-text-password-in-powershell/

Best regards,



Érica Poirier

signaturesignature

Clock4 mths

This is great!

One small mistake though:
$computers = Get-RDMSession | where {$_.ConnectionType = "RDPConfigured"}

It should be:


$computers = Get-RDMSession | where {$_.ConnectionType -eq "RDPConfigured"}


I get this list, but how do i actually connect, the code you provide shows how to configure a credential file and all is great. But how to use it to connect to machine?

I have $credential object and a list of $computer:
$credential = New-Object System.Management.Automation.PSCredential($username, $passwd)

But how I can use those credentials to connect to actual machine from the list?

The WMI command does not work with error, even though this server has conenction type "RDPConfigured"
it shows error:
Get-WMIObject : The RPC server is unavailable


Code i have so far:


$credsession = Get-RDMSession -Name "A machine name"
$username = Get-RDMSessionUserName -Session $credsession
$password = "password" | ConvertTo-SecureString -asPlainText -Force

$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Get-WMIObject win32_logicaldisk -ComputerName $credsession -Credential $credential

Clock4 mths

Hello,

Thank you for pointing out the mistake. Fixed!

The Get-WMIObject cmdlet will try to contact the remote computer specified with the -ComputerName switch.

In the provided commands, the $computers variable contains the list of remote machines. The $credsession contains the RDM credential entry object you want to use to connect on the remote computer, not the remote machine name.

So here what the script should be as it needs to loop across all computers.

* Get all RDP entries from RDM
$computers = Get-RDMSession | where {$_.ConnectionType -eq "RDPConfigured"}

* Get the main credential to connect on those machines
$credsession = Get-RDMSession -Name "MyAdminCredential"
$username = Get-RDMSessionUserName -Session $credsession
$passwd = Get-RDMSessionPassword -Session $credsession
$credential = New-Object System.Management.Automation.PSCredential($username, $passwd)

foreach ($computername in $computers)
{
$result = Get-WMIObject win32_logicaldisk -ComputerName $computername -Credential $credential
}

Then, in the foreach loop, you will have to save the content of the $result variable where you want (file, array, etc)

Best regards,



Érica Poirier

signaturesignature

Clock4 mths

Thank you for suggestion! smile

I've tried suggested approach and it showed me an error, is there any other way i coudl open a connection, using your commandlets maybe?:


$result = Get-WMIObject win32_logicaldisk -ComputerName $computername -Credential $credential

$computername.ConnectionType
Get-WMIObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:11
+ $result = Get-WMIObject win32_logicaldisk -ComputerName $computername ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (smile [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

RDPConfigured

Clock4 mths

Hello,

The reason why you get this error is because maybe a firewall rule or some privileges are missing to open a connection to that remote machine through WMI. Here are few Microsoft articles that will provide some information about WMI Connection.
https://docs.microsoft.com/en-us/windows/desktop/WmiSdk/connecting-to-wmi-remotely-starting-with-vista
https://docs.microsoft.com/en-us/windows/desktop/WmiSdk/connecting-to-wmi-on-a-remote-computer

Best regards,



Érica Poirier

signaturesignature

Clock4 mths

Erica,

So it seems there are no other way to connect trough RDM session to server?


I can run wmi and invoke-command on the test enviroment but production is a lot more secure.

I thought i could leverage RDM commandlets to connect to server that i can open RDM connections trough the application, without the need of changing the settings in remote server firewalls(which is a security risk), this is the main thing i am trying to achieve.

Clock4 mths

Hello,

You could use the Invoke-RDMLoadFromInventorySession to update the Information of each entry using the Load from Inventory and then browse through all your RDP entries to build the report. The Drives property can be accessed using $session.MetaInformation.Drives. Is it a good solution for what you want to achieve?


image

Best regards,



Érica Poirier

signaturesignature

Clock4 mths