Forum / Remote Desktop Manager - PowerShell Repository

Get-RDMSession Error Suppression

  • Create an Issue
  • Cancel


Hi,

I have a script that reads all of out VMs out of vSphere, and creates RDP or SSH Sessions within RDM. After getting the list of VMs, the process calls Get-RDMSession to test if that session already exists within RDM.
$Exists = Get-RDMSession -Name $VMList[0].Name -Group $VMlist[0].GroupName

What is causing a problem is the situation when that Session does not exist. I have tried the following to suppress the error from displaying:
$Exists = Get-RDMSession -Name $VMList[0].Name -Group $VMlist[0].GroupName -ErrorAction Ignore
$Exists = Get-RDMSession -Name $VMList[0].Name -Group $VMlist[0].GroupName -ErrorAction Stop
$Exists = Get-RDMSession -Name $VMList[0].Name -Group $VMlist[0].GroupName | Out-Null

I have tried wrapping this in a Try/Catch but all to no avail. The error always displays on the screen.

Any ideas?

This has been tried on the latest version (2019) on both Server 2012R and Win 10.


Thanks,
Des


Clock6 mths

Hello,

On my side, I succeeded including it in a try catch like this :


PS C:\RemoteDesktopManager\Devolutions.RemoteDesktopManager.Bin.13.9.14.0> try {Get-RDMSession -Name "doesnotexist"} catch {write-host "session does not exist"}
session does not exist
PS C:\RemoteDesktopManager\Devolutions.RemoteDesktopManager.Bin.13.9.14.0>


Also, Instead of setting parameters, you could pipe and filter the results:
$sessions = Get-RDMSession | where{$_.Name -eq $VMList[0].Name -and $_.Group -eq $VMlist[0].GroupName}
if ($sessions.Count -gt 0)
...

That said, have you read about synchronizers? (https://help.remotedesktopmanager.com/entrytype_synchronizer.htm)
It seems like you're trying to do exactly what synchronizers are made for...

Thanks for letting us know.

Best regards,



Alex Belisle

signaturesignature

Clock5 mths

Strange situation. First time I ran your cmdlet:
try {Get-RDMSession -Name "doesnotexist"} catch {write-host "session does not exist"}


It still gave me an error, then it worked as expected.it, including this morning.


As for the Synchronizer, I had not found that feature. I tried it with VMWare, and it did sync all the VMs. However, there are two problems.
- it did not create the folder structure. All VMs were dropped into a single folder.
- you can only have one connection type - VMConsole, or RDP. I have Windows and Linux, so I want them to have either RDP or SSH based on the guest OS.


Guess for now, I'll have to stick to my Powershell script.


Thanks,

Des

Clock5 mths

Hello,

Thanks for the feedback, I'm sorry the Synchronizer is not what you're looking for.
That said, and to get back to your script, using the pipe "|" would be the best way to use IF Exist technique.

Let us know if we can do anything else!

Best regards,



Alex Belisle

signaturesignature

Clock5 mths