Hi,
We are currently trying to clean up our "Default" vault. In order to do so, we've written a PowerShell script that will create a vault for each home folder within the Default vault. (If it doesn't already exist)
We then try to copy the sub-folder structure from each main folder into each vault by use of Copy-RDMSession . We also modify each entry's group in accordance to the folder structure change :
$CopyInstructions = foreach($Session in $Sessions){
$Copy = Copy-RDMSession $Session -IncludePasswordHistory -IncludeSubConnections
$Copy.Group = $Copy.Group.Replace("$MGroup\","") # This is to account for the loss of the main folder within the new vault
$copy
} But upon attempting to move into the "Destintation Vault" we're confronted with the following error:
The exact commands being :
$Repo = Get-RDMRepository -Name $DestinationVault Set-RDMCurrentRepository $Repo
Running the commands manually works as expected.
I have also tried adding a delay between the 2 commands by doing the following :
$Repo = Get-RDMRepository -Name $DestinationVault Start-Sleep 3 Set-RDMCurrentRepository $Repo
But to no avail.
Do you know how we could avoid this behaviour and/or are we doing something wrong?
Best regards,
Alexis De Jaeger
Technical information :
PowerShell Version = 5.1.22000.653
RemoteDesktopManager module version = 2022.2.0.0
RDM version = Entreprise Edition 2022.2.16.0 64-bit
DateSource = Devolutions Server
Hello,
Thank you for reporting this problem.
Could you please provide the whole error message?
What does the $DestinationVault variable contains during the script execution?
Best regards,
Érica Poirier
Hi Erica,
My apologies for the confusion.
The screenshot does contain errors, but not any related to the commands. Running the commands shows the banner, but nothing more. Trying to run Get-RDMCurrentRepository reveals the vault change didn't take place.
As for the $DestinationVault variable, it contains the name of the vault to which the given session needs to be moved, based on its "Home folder".
This would be a before and after the script :
Before:
Default (Vault) |__Folder 1: | |__Folder 1.1: | |__Session 1 | |__Session 2 | |__Folder 2: |__Folder 2.1: | |__Session 1 | |__Folder 2.2: |__Session 2
After:
Folder 1: (Vault) |__Folder 1.1: |__Session 1 |__Session 2 Folder 2: (Vault) |__Folder 2.1: | |__Session 1 | |__Folder 2.2: |__Session 2
Depending on the state of the loop, $DestinationVault would be "Folder 1" or "Folder 2".
You can find the full script here if it may be of any help.
Best regards,
Alexis De Jaeger
Hi Alexis,
Thank you for your feedback and your script.
I tested it on my DVLS data source and ran into some minor issues.
First, this line generate a list of folder names. But on my data source, I get an empty element.
$MainGroups= ($Entries|Where-Object{$_.Group-notmatch"\\|Test"} |Select-Object Group -Unique).Group
So I have replaced it with this one instead.
$MainGroups = ($Entries | Where-Object {$_.ConnectionType -eq "Group" -and (($_.Group).Split("\").GetUpperBound(0) -eq 0) -and ($_.Group -notmatch "\\|Test")} | Select-Object Group -Unique).Group
Then I realize that for the folders and sessions creation, the Set-RDMRepository will save the vault object and will not switch on that vault. I have replaced it with Set-RDMCurrentRepository cmdlet and folders were properly created in the destination vault.
For the sessions, there is an issue with the command to fetch the entries. I will have to verify because some of them are missing.
One other thing I realize is that the activity logs for the folders and the entries are not migrated to the newly created entries. Is it correct if the logs aren't transferred?
And how many folders will you move to separated vaults?
Would it be easier if you use the Move to vaults feature available in the Edit menu?
Best regards,
Érica Poirier
Hi Alexis,
I found out that the $Sessions variable doesn't contains all session under a top level folder. The variables only contains entries that are located in a sub folder.
So from this command :
$Sessions = $Entries | Where-Object{$_.ConnectionType -ne "Group" -and $_.Group -match "\\"} | Sort-Object Group
I have updated it to :
$Sessions = $Entries | Where-Object{$_.ConnectionType -ne "Group" -and $_.Group -notlike ""} | Sort-Object Group
The Group property of an entry located under a top level folder will only contains the folder's name without the "\".
Let me know if that helps.
Best regards,
Érica Poirier
Hi Erica,
Thank you for your reply.
Regarding you different questions :
$MainGroups= ($Entries|Where-Object{$_.Group-notmatch"\\|Test"} |Select-Object Group -Unique).Group Generating an empty list:I don't have the issue when running it on our data-source. The "home" folder having no parent folder, they should be the only one returned. I cannot explain why you don't have a return without having more information regarding the repository you're running it on.
I will be replacing it by : $MainGroups = ($Entries | Where-Object{$_.Group -eq $_.Name} | Select-Object Group -Unique).Group
Should be a lot more efficient when having to deal with many folders.
Well, this is awkward. Somehow using the right command, does give you the expected results... I've corrected the command and it does now change to the required Repository :) .
I'm unaware of a switch allowing us to do so. Running Get-Help Copy-RDMSession -Full only returned the switches : IncludePasswordHistory , IncludeSubConnections. I saw in one of your previous posts that using -DontChangeID would result in the sessions to be moved instead of copied over. (Which we don't want to do atm)
If there is a way to preserve logs while copying the sessions over, I would be interested :)
We might be limit-testing the extents of the PowerShell module with this. Our "Main Vault" currently has 371 "Main folders", each would need to have their separate vault.
On average we would have 34 session within each of the "Main folders" that would need to be copied over to their corresponding vault.
The GUI would be easier, but quite costly in terms of time to invest. Which is why we were exploring the possibility to do it with the PowerShell module.
We're currently testing things out and I'm still seeing how I can optimise the script. For example : Line 93 to 103 :
foreach($MGroup in $MainGroups){
$GroupSessions = $Sessions | Where-Object{$_.Group -like "$MGroup\*"}
$SessionCreation = foreach($Folder in $GroupSessions){
$Copy = Copy-RDMSession $Folder -IncludePasswordHistory -IncludeSubConnections
$Copy.Group = $Copy.Group.Replace("$MGroup\","") # New vault doesn't have the first folder level structure
$Copy
}
Set-RDMRepository (Get-RDMRepository -Name $MGroup)
$SessionCreation | ForEach-Object{Set-RDMSession $_}
Set-RDMCurrentRepository $MVInfo
}Used to move the sessions one by one, changing the current repository from the "Main repository" to the target vault and back on every session. This was quite slow, so I tried grouping the contents of the move into a variable, prior to changing the current repository.
If you see any optimisation that could be done, feel free to mention them :)
This is intentional and the result of a discussion with Alexandre Bélisle from your Service Desk Team (Ticket 00006950). I had originally contacted them as I failed at using Copy-RDMSession , but I have since found how to use it properly. (I forgot to adapt the group parameter to the destination's vault folder structure)
He then suggested I copy the folder structure over, prior to moving over the sessions, in order to prevent any errors. This is why there is a distinction between "Sessions" and "Folders". Creating the folder structure within the target vault prior to attempting to recreate the cessions.
If anything isn't quite clear, feel free to ask.
I will adapt the script in accordance to your suggestions and will try to run it again. I will keep you updated on the results.
Thank you for your help.
Best regards,
Alexis De Jaeger
Hi Alexis,
Thank you for your feedback.
Here are some additional information and some replies to the topics.
$Sessions = $Entries | Where-Object{$_.ConnectionType -ne "Group" -and $_.Group -notlike ""} | Sort-Object Group
Let me know how it goes with the updated script.
Best regards,
Érica Poirier
Hi Erica,
Thank you for your reply.
Regarding your points:
Sadly, I don't really see why that would return an empty value. The new statement should only return valid "Home folders". I will be waiting for your feedback with the recent changes.
We are aware of that option, but the goal in the current phase is to test out the performance of the PowerShell module. Considering the amount of date that needs to be moved around we will first proceed with a copy, as to keep our Default vault as backup in the worst case scenario. (We do have backups, but better safe than sorry :) ).
Once the copy will be tested out and evaluated, we will consider the move ("-DontChangeId") as keeping the logs would be interesting.
I won't deny being quite reassured hearing this, as I spent a considerable time researching and writing the script. But as stated above, we will first test the extent / reliability of the PowerShell module prior to applying it to our production Vault.
Would you have any suggestions regarding the execution of the script?
We planned to do so outside of workhours in order to minimise user interactions with the vault while the script is running.
Should we keep the Remote Desktop Manager client running while the script is running or should we just run it using the PowerShell module? (I would guess that would render the "Update-RDMUI" pointless, but I would like to minimise the impact on the vault/datasource while the script is running)
Good point. We actually don't have that type of folder configuration within our default vault, but I do see why they would be missing. I'll update the script accordingly.
Best regards,
Alexis De Jaeger
Hi Alexis,
Thank you for your reply.
Let me know how it goes once you will test the script.
Best regards,
Érica Poirier
Hi Érica,
Sorry for the late update.
Wanting to implement a few additional features caused a few bugs, which basically resulted in having to rewrite 1/3 of the script :D
All testing so far has been successful. I'm quite pleasantly surprised at the speed at which the changes can be made, but this is only working with a test vault with only 11 entries.
We should have the necessary approvals to run it on the production vault during next week. But even then, I might separate the task into a few smaller batches.
If all that is successful and if it is approved, I will also try to implement the "move" into the script.
Thank you anyways for your help and feedback.
Best regards,
Alexis De Jaeger
Hi Alexis,
Thank you for your feedback.
Let me know how the script will work once you will run the script on a larger vault and even on your production vault.
Best regards,
Érica Poirier