Forum / Remote Desktop Manager - PowerShell Repository

Get-RDMSession unlucky behavior if no session matches

  • Create an Issue
  • Cancel

Hi There,
I've just tried Get-RDMSession, but I'm very unhappy with the behavior of how the command response if no session is matched.

Get-RDMSession : Cannot validate argument on parameter 'Name'. The argument "Butinar_Janos" does not belong to the set "mysession1,mysession2,mysession3[...full list of sessions...]".

Why don't you return sth like get-Item:


Get-Item : Cannot find path 'C:\notexisting' because it does not exist.
At line:1 char:1
+ Get-Item -Path "c:\notexisting"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\notexisting:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand


Further I would prefer to simply retrieve an empty list/$null

Best regards,
Christian

Clock3 yrs

Hi,

The parameter Name is a parameter with a ValidateSet created dynamically. The reason why we created the parameter Name is to get a session with the name without having to write a Where-Object each time and be able to use TAB to navigate through the sessions with the parameter. As you noticed when you use this parameter and the value you give doesn't exist in the ValidateSet, you will get an error that the argument that you gave doesn't belong to the set.

The error is thrown by PowerShell itself and it seems to not have a way to silent it or modify it. I understand the error takes a lot of place in the console if you have a lot of sessions in the data source.

You don't have to use this parameter to get a session by its name, I would say to use Get-RDMSession with a Where-Object that will return null if the cmdlet doesn't find a session with the condition given.
Ex:

 $session = Get-RDMSession | Where-Object {$_.Name -eq "SessionName"}

Best regards,

Olivier Désalliers

signaturesignature

Clock3 yrs