Forum / Remote Desktop Manager - PowerShell Repository

Copy RDM Session to another datasource

  • Create an Issue
  • Cancel

Hello,


I'm trying to set up a powershell script to copy all the structure of a folder with its credentials into another data source.

I started the script but when I execute it, only the folders are copied. Can you help me ?

Example of structure :

FOLDER1
FOLDER1\folder
FOLDER1\folder\loginwindows
FOLDER1\folder\windows1
FOLDER1\folder\windows2
FOLDER1\folder\folder\loginLinux
FOLDER1\folder\folder\Linux1
FOLDER1\folder\folder\windows3
FOLDER2
FOLDER2\BB
FOLDER2\BB\Linux4

Script :

#PARAMETRE
$GroupName = 'FOLDER1'
$SecuGroup2 = 'GUID SecurityGroup'
$DataSource1 = 'GUID datasource1'
$DataSource2 = 'GUID datasource2'

#datasource active : 1
Set-RDMCurrentDataSource -id $DataSource1
$sessions = Get-RDMSession -groupname $GroupName -IncludeSubFolders

#Change SecurityGroup
foreach ($sess in $sessions){$sess.SecurityGroup = $SecuGroup2}


$sessions2 = copy-rdmsession -PSConnection $sessions

#datasource active : 2
Set-RDMCurrentDataSource -id $DataSource2
set-rdmsession $sessions2


Thanks
Best Regards

Clock4 mths

Hello,

I found my mistake I had to add -session in set-rdmsession.

I'm blocking now, I'm trying to rename the main folder and that it is resolved throughout the structure :

FOLDER1
FOLDER1\folder
FOLDER1\folder\loginwindows
FOLDER1\folder\windows1
FOLDER1\folder\windows2
FOLDER1\folder\folder\loginLinux
FOLDER1\folder\folder\Linux1
FOLDER1\folder\folder\windows3


to


NEW FOLDERNAME
NEW FOLDERNAME\folder
NEW FOLDERNAME\folder\loginwindows
NEW FOLDERNAME\folder\windows1
NEW FOLDERNAME\folder\windows2
NEW FOLDERNAME\folder\folder\loginLinux
NEW FOLDERNAME\folder\folder\Linux1
NEW FOLDERNAME\folder\folder\windows3

The script with correction


#PARAMETRE
$GroupName = 'FOLDER1'
$SecuGroup2 = 'GUID SecurityGroup'
$DataSource1 = 'GUID datasource1'
$DataSource2 = 'GUID datasource2'

#datasource active : 1
Set-RDMCurrentDataSource -id $DataSource1
$sessions = Get-RDMSession -groupname $GroupName -IncludeSubFolders

#Change SecurityGroup
foreach ($sess in $sessions){$sess.SecurityGroup = $SecuGroup2}


$sessions2 = copy-rdmsession -PSConnection $sessions

#datasource active : 2
Set-RDMCurrentDataSource -id $DataSource2
set-rdmsession -session $sessions2

Clock4 mths


Hello,

To rename the folder, you can do it before saving the session in the destination data source.

Here is a part of your script with the folder update code.


...
#datasource active : 2
Set-RDMCurrentDataSource -id $DataSource2
# Update the folder
$folder = $session2.Group
$folder = $folder.Replace('FOLDER1, 'NEW FOLDERNAME')
$session2.Group = $folder
if ($session2.Name -eq "FOLDER1"wink
{
$session2.Name = "NEW FOLDERNAME"
}

set-rdmsession -session $sessions2



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock4 mths

Thanks for your feedback. I managed using another function. I share my code if it can help other people.

I will now assigne the security group created to a user. I use the "Set-RDMUserGroupRights" function that does not work.
in the doc https://help.remotedesktopmanager.com/index.html?powershell_cmdlets.htm , the function $groups = Get-RDMGroup dont exist. I replace it by get-RDMSecurityGroup.


$users = Get-RDMUser; $groups = Get-RDMSecurityGroup; Set-RDMUserGroupRights -user $users[0] -SecurityGroup $groups[0] -Add -Delete
Missing an argument for parameter 'Add'


i testing :
$users = Get-RDMUser; $groups = Get-RDMSecurityGroup; Set-RDMUserGroupRights -user $users[0] -SecurityGroup $groups[0] -Add 0 -Delete 1
no error, but nothing are change.


Can you help me ?
EDIT : i managed using this argument :

$userslogin = "login users"
$users = Get-RDMUser | where {$_.Name -eq $userslogin}

Set-RDMUserGroupRights -user $users -SecurityGroup $securityGroup -View $true
Set-rdmuser $users

The script :

############################################################### PARAMETER TO CHANGE ################################
$GroupName = 'add your groupname'
$ExpirationAcces = '06/26/2019 18:00:00'
$ticket = '1234567'


############################################################### PARAMETER ################################
$ExpirationStatusExpire = '{7B926104-9C7E-4c91-BDAC-DFCCC36B8D70}'
$ExpirationStatusDefault = ''
$DatasourceActive = ''
$DataSource1 = 'guid datasource 1'
$DataSource2 = 'guid datasource 2'
$date = (Get-Date).ToString()


############################################################### check ################################


$DatasourceActive = get-RDMCurrentDataSource
if ($DatasourceActive.ID -eq $DataSource1){Write-Host "Datasource active 1 OK" `n -foregroundcolor "Green"}ELSE{Set-RDMCurrentDataSource -id $DataSource1}


############################################################### RECUPERATION DES INFOS SUR LA DATASOURCE 1 ################################


##copie de la structure dossier
$sessionsGroup = Get-RDMSession -groupname $GroupName -IncludeSubFolders | Where-Object {$_.ConnectionType -eq "Group"}


##copie des sessions hors dossier
$sessions = Get-RDMSession -groupname $GroupName -IncludeSubFolders | Where-Object {$_.ConnectionType -ne "Group"}


############################################################### CONNEXION DATASOURCE 2 ET MAJ ################################
#datasource active : 2
Set-RDMCurrentDataSource -id $DataSource2


##Création du groupe de Sécurité
$NameSecuGroup = $groupname + "_" + $ticket + "_" + $date
$securityGroup = New-RDMSecurityGroup -Name $NameSecuGroup ;Set-RDMSecurityGroup $securityGroup


############################################################### CHANGEMENT EN VARIABLE AVANT TRANSFERT SUR DATASOURCE 2 ################################
#Modification SecurityGroup
$SecuGroup2 = $securityGroup.ID
foreach ($sessGroup in $sessionsGroup){$sessGroup.SecurityGroup = $SecuGroup2}
foreach ($sess in $sessions){$sess.SecurityGroup = $SecuGroup2}


#Modification Expiration Status---> dossier / Date--> session
foreach ($sessGroup in $sessionsGroup){$sessGroup.Status = $ExpirationStatusExpire}
foreach ($sess in $sessions){$sess.MetaInformation.Expiration = $ExpirationAcces}


##Création de la structure Dossier
$sessions2 = copy-rdmsession -DontChangeID -PSConnection $sessionsGroup
set-rdmsession -session $sessions2


##Création de la structure session
$sessions2 = copy-rdmsession -DontChangeID -PSConnection $sessions
set-rdmsession -session $sessions2


############################################################### Modification nom du dossier principal SUR DATASOURCE 2 ################################
$sessDossier = $sessionsGroup | where {$_.name -eq $groupname}
$newdossier = $groupname + " - " + $ticket + " - Expire : " + $ExpirationAcces
Rename-RDMGroup -Session $sessDossier -NewGroupName $newdossier


############################################################### SecurityGroup to user : ERROR ################################

$userslogin = "login users"
$users = Get-RDMUser | where {$_.Name -eq $userslogin}

Set-RDMUserGroupRights -user $users -SecurityGroup $securityGroup -View $true
Set-rdmuser $users


Clock4 mths


Hello,

Have been able to get your script working with the modifications you have made?

If not, what behavior do you want to get?

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock4 mths

Hello Erica,

My script does not work properly.
The aim is to copy a folder with subfolders and sessions in another database.
By modifying:
- The name of the main folder
- create a new security group and linked it to a user.

In fact, the script works unless you copy the same folder a second time.
If I leave the "-DontChangeID" parameter, it replaces instead of adding a new folder.
Removing the "-DontChangeID" parameter I lose the link with credentials in sessions

My problem is especially with the link with the credentials when copying the folder for the second time.
Can you help me ?
The latest version script :


############################################################### PARAMETER TO CHANGE ################################
$GroupName = 'add your groupname'
$ExpirationAcces = '07/04/2019'
$ticket = '99999'
$userslogin = "login users"

############################################################### PARAMETER ################################
$DatasourceActive = ''
$DataSource1 = 'guid datasource 1'

$DataSource2 = 'guid datasource 2'
$date = (Get-Date).ToString()

############################################################### check ################################


$DatasourceActive = get-RDMCurrentDataSource
if ($DatasourceActive.ID -eq $DataSource1){Write-Host "Datasource active 1 OK" `n -foregroundcolor "Green"}ELSE{Set-RDMCurrentDataSource -id $DataSource1}


############################################################### RECUPERATION DES INFOS SUR LA DATASOURCE 1 ################################

##Session du dossier principal
$sessionsAll = Get-RDMSession -groupname $GroupName -IncludeSubFolders

##copie de la structure dossier
$sessionsGroup = $sessionsAll | Where-Object {$_.ConnectionType -eq "Group"}


##copie des sessions hors dossier
$sessions = $sessionsAll | Where-Object {$_.ConnectionType -ne "Group"}


############################################################### CONNEXION DATASOURCE 2 ET MAJ ################################
#datasource active : 2
Set-RDMCurrentDataSource -id $DataSource2


##Création du groupe de Sécurité
$NameSecuGroup = $GroupName + "_" + $ticket + "_" + $date
$securityGroup = New-RDMSecurityGroup -Name $NameSecuGroup ;Set-RDMSecurityGroup $securityGroup


############################################################### CHANGEMENT EN VARIABLE AVANT TRANSFERT SUR DATASOURCE 2 ################################
#Modification SecurityGroup
$SecuGroup2 = $securityGroup.ID
foreach ($sessGroup in $sessionsGroup){$sessGroup.SecurityGroup = $SecuGroup2}
foreach ($sess in $sessions){$sess.SecurityGroup = $SecuGroup2}


#Modification Expiration Date
foreach ($sess in $sessionsAll){$sess.MetaInformation.Expiration = $ExpirationAcces}


##Création de la structure Dossier
$sessions2 = copy-rdmsession -DontChangeID -PSConnection $sessionsGroup
#$sessions2 = copy-rdmsession -PSConnection $sessionsGroup
set-rdmsession -session $sessions2


##Création de la structure session
$sessions2 = copy-rdmsession -DontChangeID -PSConnection $sessions
#$sessions2 = copy-rdmsession -PSConnection $sessions

set-rdmsession -session $sessions2


############################################################### Modification nom du dossier principal SUR DATASOURCE 2 ################################
$sessDossier = $sessionsGroup | where {$_.name -eq $GroupName}
$newdossier = $GroupName + " - " + $ticket + " - Expire : " + $ExpirationAcces
Rename-RDMGroup -Session $sessDossier -NewGroupName $newdossier


############################################################### SecurityGroup to user ################################

$users = Get-RDMUser | where {$_.Name -eq $userslogin}

Set-RDMUserGroupRights -user $users -SecurityGroup $securityGroup -View $true
Set-rdmuser $users


Clock4 mths


Hello,

Let me check your last script version and will get back to you next week with a solution or some guidance about it.

What RDM version are you using?

What data source type are you connected to? If it's Devolutions Password Server, what version are you using?

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock4 mths

Hello Erica,

Thanks for your feedback.

I use the version of RDM 13.6.7 connected on SQL Server

Best regards,

Clock4 mths

Hello,

For information, I have the same problem if I perform the export and import of sessions manually.
I think this is due to the link of credentials that is done via the guid.
Is it possible to copy the data with new guidelines while keeping the link with the credentials?

Thanks for your feedback.


Best Regards.

Clock4 mths


Hello,

When we export the sessions from one data source and import them into another data source, the credentials settings are still the same as the original. I am unable to reproduce the issue you are experiencing.

About your script, first of all, when you want to set a data source as the current one, using the name of the data source will not work. Here is a good method to set a data source as the current one. I have update the Check section of your own script. You can use the same code to switch to the data source 2.


############################################################### check ################################
$DatasourceActive = get-RDMCurrentDataSource
if ($DatasourceActive.Name -eq $DataSource1)
{
Write-Host "Datasource active 1 OK" `n -foregroundcolor "Green"
}
else
{
$ds1 = Get-RDMDataSource -Name $DataSource1
Set-RDMCurrentDataSource $ds1
}

About the update of the entries, as by default the Security Group will be inherited, there is no need to set it on all individual entries. Only updating the top parent folder should be enough if all children entries will use the same security group, even sub folders.

I haven't finished to analyze your script. Once it will be ready, I will post it here.

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock4 mths


Hello,

Here is the updated script. All link to credentials are working in the destination data source. So the issue you are experinecing is maybe related to something else. I would recommend you to send an email to ticket@devolutions.net and we will help you to troubleshoot the credential issue.


############################################################### PARAMETER TO CHANGE ################################
$GroupName = 'add your groupname'
$ExpirationAcces = '07/04/2019'
$ticket = '99999'
$userslogin = "login users"

############################################################### PARAMETER ################################
$DatasourceActive = ''
$DataSource1 = 'name datasource 1'

$DataSource2 = 'name datasource 2'
$date = (Get-Date).ToString()

############################################################### check ################################
$DatasourceActive = get-RDMCurrentDataSource
if ($DatasourceActive.Name -eq $DataSource1)
{
Write-Host "Datasource active 1 OK" `n -foregroundcolor "Green"
}
else
{
$ds1 = Get-RDMDataSource -Name $DataSource1
Set-RDMCurrentDataSource $ds1
}

############################################################### RECUPERATION DES INFOS SUR LA DATASOURCE 1 ################################

##Session du dossier principal
$sessionsAll = Get-RDMSession -groupname $GroupName -IncludeSubFolders

############################################################### CONNEXION DATASOURCE 2 ET MAJ ################################
#datasource active : 2
$ds2 = Get-RDMDataSource -Name $DataSource2
Set-RDMCurrentDataSource $ds2

#Modification Expiration Date
foreach ($sess in $sessionsAll){$sess.MetaInformation.Expiration = $ExpirationAcces}

## Sauvegarder les sessions dans la datasource 2
$sessionsGroup = $sessionsAll | Where-Object {$_.ConnectionType -eq "Group"}
Set-RDMSession -Session $sessionsGroup -Refresh
$sessions = $sessionsAll | Where-Object {$_.ConnectionType -ne "Group"}
Set-RDMSession -Session $sessions -Refresh

## Création du groupe de Sécurité
$NameSecuGroup = $GroupName + "_" + $ticket + "_" + $date
$securityGroup = New-RDMSecurityGroup -Name $NameSecuGroup
Set-RDMSecurityGroup $securityGroup

## Assigner le groupe de sécurité au dossier parent
$sessDossier = Get-RDMSession -Name $GroupName | where {$_.ConnectionType -eq "Group"}
$sessDossier.SecurityGroup = $securityGroup.ID
Set-RDMSession -Session $sessDossier -Refresh

$newdossier = $GroupName + " - " + $ticket + " - Expire : " + $ExpirationAcces
Rename-RDMGroup -Session $sessDossier -NewGroupName $newdossier

############################################################### SecurityGroup to user ################################

$users = Get-RDMUser | where {$_.Name -eq $userslogin}

Set-RDMUserGroupRights -user $users -SecurityGroup $securityGroup -View $true
Set-rdmuser $users

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock4 mths


Hello,

Thanks very much for your feedback.

Security groups are present in Datasource1 but nonexistent in Datasource2. Errors are then reported.

To avoid errors I added the following part before the Set-RDMSession to run the script:


#Modification SecurityGroup '00000000-0000-0000-0000-000000000000'
foreach ($sess in $sessionsAll){$sess.SecurityGroup = '00000000-0000-0000-0000-000000000000'}

It works unless I restart the script with the same name $ groupname, which replaces the first copied folder.
I have the same behavior as before

Example:
First launch:
$ GroupName = 'FOLDER TOTO'
$ ExpirationAcces = '07/10/2019 '
$ ticket = '222222'
$ userslogin = "USER1"

The copy works on the Datasource2 with the name of the folder:
'FOLDER TOTO - 222222 - Expires 10/07/2019'

Second launch:
$ GroupName = 'FOLDER TOTO'
$ ExpirationAcces = '08/15/2019 '
$ ticket = '888888'
$ userslogin = "USER2"

The copy works on the Datasource2 but replaces the first launch.
'FOLDER TOTO - 888888 - Expire 08/15/2019'

How can we make it add to it?
'FOLDER TOTO - 222222 - Expire 10/07/2019'
'FOLDER TOTO - 888888 - Expire 08/15/2019'


managed to have both files by asking to change the IDs, However this is where the problem arises with the links of the identifiers repositories


Thank you again for your precious help, it is really very appreciable.

Have a good day


Michel

Clock4 mths


Hello,

I have added the part to remove the security group before creating a copy of the entries. Instead of running two foreach loops to update the expiration date and removing the security group, I use the same loop.

To get another copy of all entries without replacing the existing entries in the destination data source, I have modified the code like the following. But because -NoNewGUID switch isn't used to create new GUIDs, the credential settings aren't updated in the sessions where the credentials are configured. I will check with an engineer what we can do about it and will get back to you once I will get an update.



############################################################### CONNEXION DATASOURCE 2 ET MAJ ################################
#datasource active : 2
$ds2 = Get-RDMDataSource -Name $DataSource2
Set-RDMCurrentDataSource $ds2

#Modification Expiration Date et retirer groupe de sécurité
foreach ($sess in $sessionsAll)
{
$sess.MetaInformation.Expiration = $ExpirationAcces
$sess.SecurityGroup = '00000000-0000-0000-0000-000000000000'
}

## Sauvegarder les sessions dans la datasource 2
$sessionsGroup = $sessionsAll | Where-Object {$_.ConnectionType -eq "Group"}
$sessions = $sessionsAll | Where-Object {$_.ConnectionType -ne "Group"}
$sessionsTmp = $sessionsGroup + $sessions
$sessionsNewID = Copy-RDMSession -PSConnection $sessionsTmp
Set-RDMSession -Session $sessionsNewID -Refresh

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock3 mths


Hello,

So even using the Clipboard - Copy - Change ID feature from the RDM UI will not switch the new IDs in the Credential Repository property of any entry. I have sent a ticket to our engineering team and once I will get an update, I will let you know.

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock4 mths


Hello,

That's exactly my problem, thanks for your investigation. I'm waiting for the return of your engineering team.

Best regards

Clock3 mths

Hello,
Did you have a feedback from your engineering team ?

Thanks for your help

Best regards

Clock3 mths


Hello,

Sorry but I didn't get any feedback from the engineering team about this behavior. I will ask if it is possible to increase the priority on this ticket. By the way, I forgot to give you the internal ticket nemuber RDMW-3251 for future references.


Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock3 mths

Hello,

The issue has been fixed internally about the ID of the credential entries that were not kept in the entries. The next RDM version 2019.2.x will contain that fix. It should be available later this fall.

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock2 mths

Thank you for your return, we look forward to the release of the fix.
Best Regards

Clock2 mths


Hello,

RDM version 2019.2.3 is already available to download as a beta version on the following page.
https://remotedesktopmanager.com/home/download#Beta

Please note that this version will require to update your SQL database. As you are using RDM 13.7.6, I would first recommend you to test that version in a staging environment connected to a test SQL database. It is also possible to install the newest RDM version 2019.2.3 as a portable version. You will find the instruction on the following help page.
https://help.remotedesktopmanager.com/installation_portableusb.htm

Best regards,



Érica Poirier

OFFICE CLOSURE!
Although our various support queues will be monitored for emergencies, Devolutions' offices will be closed on October 14th 2019.

signaturesignature

Clock2 mths