Create entry via PowerShell using an ID instead of a Group path

Create entry via PowerShell using an ID instead of a Group path

avatar

Hello,

we are currently automatically creating RDM entries using a PowerShell script, which works well enough, but encountered the issue that someone renamed a folder and thus broke our automation process, because in order to create the entry we are defining the "Group" for the entry, which is the absolute path where the entry should get created.

So the basic logic looks something like this:

$groupstring = $rootfolder + "\subfolder"
$session = New-RDMSession -Name $rdm_entry_name -Type "WebBrowser" -Group $groupstring


We hardcode the "subfolder" part here and if someone changes it to "subfolder_1" in RDM the entries can't get created, because the string no longer points to an actual destination.

Since every entry in RDM has an ID is it possible to use this ID as a destination to create entries under or is the Group parameter the only way to specifiy where an entry should get created? Or another question: Is there a better way than using the absolute path to specify a destination for an entry so that a simple rename doesn't break the process?

Hope someone can help me with this.

All Comments (6)

avatar

Hi KevGue,

A way to avoid breaking your script is to get the subfolder with the Get-RDMSession and pass its group property to the group parameter.

$subFolder = Get-RDMSession -ID theSubfolderID
$session = New-RDMSession -Name $rdm_entry_name -Type "WebBrowser" -Group $subFolder.Group

This should give the result you desire as long as the subFolder is not renamed while the script is running. If it is not satisfactory, I will keep looking.

Maxime Bernier

avatar

Hello,

the Get-RDMSession cmdlet does not have an ID parameter:

PS C:\Users\test> (get-command get-rdmsession).parameters

Key                              Value
---                              -----
CaseSensitive                    System.Management.Automation.ParameterMetadata
GroupName                        System.Management.Automation.ParameterMetadata
IncludeDocumentsStoredInDatabase System.Management.Automation.ParameterMetadata
IncludeLocalPlaylists            System.Management.Automation.ParameterMetadata
IncludeSubFolders                System.Management.Automation.ParameterMetadata
IncludeUserSpecificSettings      System.Management.Automation.ParameterMetadata
Verbose                          System.Management.Automation.ParameterMetadata
Debug                            System.Management.Automation.ParameterMetadata
ErrorAction                      System.Management.Automation.ParameterMetadata
WarningAction                    System.Management.Automation.ParameterMetadata
InformationAction                System.Management.Automation.ParameterMetadata
ErrorVariable                    System.Management.Automation.ParameterMetadata
WarningVariable                  System.Management.Automation.ParameterMetadata
InformationVariable              System.Management.Automation.ParameterMetadata
OutVariable                      System.Management.Automation.ParameterMetadata
OutBuffer                        System.Management.Automation.ParameterMetadata
PipelineVariable                 System.Management.Automation.ParameterMetadata
Name                             System.Management.Automation.ParameterMetadata

PS C:\Users\test> get-module remotedesktopmanager

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     2022.3.0.1 remotedesktopmanager                {Add-HubGroupUser, Add-RDMPrivateSessionAttachment, Add-RD...


I even updated to the newest version on the gallery to make sure it's not a problem with my current version.

avatar

Hello,

You are right, the ID parameter does not exists. It has been added to our todo list.

For the moment, you can filter the sessions with Where-Object

$subFolder = Get-RDMSession | Where-Object -Property ID -eq theSubfolderID


If the folder is the user vault, you must use Get-RDMPrivateSession cmdlet instead of Get-RDMSession.

avatar

Hello,

thank you for this. I was able to use this to change our process and it works now.

avatar

Hi,

Happy this works for you. In the next version of the module, an ID parameter will be added to the Get-RDMSession and Get-RDMPrivateSession so you can fetch the the session directly.

Maxime Bernier

avatar

Hi.

The 2022.3.1.0 release, that has a fix for this problem, is now available.

Regards

Jonathan Lafontaine