Users

All Posts (10)

avatar

kiaarmani

Creating a new repository and importing data makes groups unavailable for a few minutes

avatar
avatar
avatar

Hello there,

We are currently facing an issue with creating a repository using a PowerShell script.

Once the script has performed its work (create repo, import data, set role assignements), all groups become unavailable for a few minutes (Administration > User Groups List is empty), and thus non of our users are able to use RDM, as all repositories disappear.

If I flush the cache in the admin panel the issue resolves immediately instead of after a few minutes.

Please let me know if and what logs you need from me to troubleshoot this. (I'm an engineer without access to the file system of the VM that runs the application or database. If you can point me to exact locations that would be appreciated)

Relevant snippet from Powershell:

function New-RepositoryFromTemplate {
    param (
        [string]$NewRepositoryName,
        [string]$TemplateRepositoryName,
        [string]$TemplateExportFile,  # optional path to cached template export
        [string[]]$AllowedRoles
    )
    try {
        $templateRepo = Get-RDMRepository -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $TemplateRepositoryName } | Select-Object -First 1
        if (-not $templateRepo) {
            Write-LogSimple -Message "Template repository '$TemplateRepositoryName' not found. Creating empty repository and importing cache if available." -Type "WARNING"
        }

        $newRepo = New-RDMVault -Name $NewRepositoryName -ErrorAction Stop -IsAllowedOffline $true -VaultContentType "Everything" -SetRepository
        if (-not $newRepo) {
            $newRepo = Get-RDMRepository -ErrorAction Stop | Where-Object { $_.Name -eq $NewRepositoryName } | Select-Object -First 1
        }
        if (-not $newRepo) { throw "Repository '$NewRepositoryName' could not be created or resolved." }
        Set-RDMCurrentRepository -Repository $newRepo -ErrorAction Stop

        if ($TemplateExportFile -and (Test-Path $TemplateExportFile)) {
            Write-LogSimple -Message "Importing template cache '$TemplateExportFile'." -Type "INFO"
            Import-RDMSession -Path $TemplateExportFile -Set -ErrorAction Stop `
                -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes) -DuplicateAction "Overwrite" | Out-Null
        } else {
            Write-LogSimple -Message "No template cache provided. Run single export/import flow if needed." -Type "WARNING"
        }

        Grant-RepositoryRoles -Repository $newRepo -RoleNames $AllowedRoles
        Write-LogSimple -Message "Template applied to '$NewRepositoryName'." -Type "INFO"
    } catch {
        Write-LogSimple -Message "Error while cloning template: $($_.Exception.Message)" -Type "ERROR"
        $existingRepo = Get-RDMRepository -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $NewRepositoryName } | Select-Object -First 1
        if (-not $existingRepo) {
            New-RDMVault -Name $NewRepositoryName -ErrorAction Stop -IsAllowedOffline $true -VaultContentType "Everything" -SetRepository | Out-Null
        }
        throw
    }
}

function Grant-RepositoryRoles {
    param (
        [Parameter(Mandatory = $true)] [psobject]$Repository,
        [string[]]$RoleNames
    )

    if (-not $Repository) { throw "Repository reference missing for role assignment." }
    $roles = $RoleNames | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_.Trim() } | Where-Object { $_ }

    if (-not $roles -or $roles.Count -eq 0) {
        Write-LogSimple -Message "No repository roles configured; skipping role assignment." -Type "INFO"
        return
    }

    try {
        $addAccessCmd = Get-Command Add-RDMRoleRepositoryAccess -ErrorAction SilentlyContinue
        if (-not $addAccessCmd) { throw "Add-RDMRoleRepositoryAccess command not available to assign roles." }

        Set-RDMCurrentRepository -Repository $Repository -ErrorAction SilentlyContinue | Out-Null
        Write-LogSimple -Message ("Assigning roles to repository '{0}' (ID: {1}; Type: {2})" -f $Repository.Name, $Repository.ID, $Repository.GetType().FullName) -Type "DEBUG"

        $resolvedRoles = New-Object System.Collections.Generic.List[object]
        foreach ($roleName in $roles) {
            $roleObj = $null
            Write-LogSimple -Message ("Resolving role '{0}'..." -f $roleName) -Type "DEBUG"
            try {
                if (Get-Command Get-RDMRole -ErrorAction SilentlyContinue) {
                    $roleObj = Get-RDMRole -Name $roleName -ErrorAction Stop | Select-Object -First 1
                }
            } catch { $roleObj = $null }

            if (-not $roleObj) {
                $available = @()
                try { $available = (Get-RDMRole -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Name) } catch { }
                Write-LogSimple -Message ("Role '{0}' not found. Available roles: {1}" -f $roleName, ($available -join ", ")) -Type "ERROR"
                throw "Role '$roleName' not found; cannot grant repository access."
            }

            Add-RDMRoleRepositoryAccess -Repository $Repository -Role $roleObj -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes) -ErrorAction Stop | Out-Null
            $resolvedRoles.Add($roleObj.Name) | Out-Null
            Write-LogSimple -Message ("Role '{0}' granted repository access." -f $roleObj.Name) -Type "DEBUG"
        }

        Write-LogSimple -Message ("Roles granted to repository '{0}': {1}" -f $Repository.Name, ($resolvedRoles -join ", ")) -Type "INFO"
    } catch {
        Write-LogSimple -Message ("Failed to assign repository roles: {0}" -f $_.Exception.Message) -Type "ERROR"
        throw
    }
}

Powershell - Unable to create repository using application identity

avatar
avatar
avatar
avatar

Hello @Christian Robert,

I have removed the call and ran the script again and it works! Thank you!

Powershell - Unable to create repository using application identity

avatar
avatar
avatar
avatar

It appears I have the same issue with Add-RDMRoleRepositoryAccess. It claims to have done it, but it actually didn't. I checked the Get-Help output for possible missing arguments, but did not find anything. I feel like I am overseeing something here again. Do I need to re-save the repo?

function Grant-RepositoryRoles {
    param (
        [Parameter(Mandatory = $true)] [psobject]$Repository,
        [string[]]$RoleNames
    )

    if (-not $Repository) { throw "Repository reference missing for role assignment." }
    $roles = $RoleNames | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_.Trim() } | Where-Object { $_ }

    if (-not $roles -or $roles.Count -eq 0) {
        Write-LogSimple -Message "No repository roles configured; skipping role assignment." -Type "INFO"
        return
    }

    try {
        $addAccessCmd = Get-Command Add-RDMRoleRepositoryAccess -ErrorAction SilentlyContinue
        if (-not $addAccessCmd) { throw "Add-RDMRoleRepositoryAccess command not available to assign roles." }

        Set-RDMCurrentRepository -Repository $Repository -ErrorAction SilentlyContinue | Out-Null
        Write-LogSimple -Message ("Assigning roles to repository '{0}' (ID: {1}; Type: {2})" -f $Repository.Name, $Repository.ID, $Repository.GetType().FullName) -Type "DEBUG"

        $resolvedRoles = New-Object System.Collections.Generic.List[object]
        foreach ($roleName in $roles) {
            $roleObj = $null
            Write-LogSimple -Message ("Resolving role '{0}'..." -f $roleName) -Type "DEBUG"
            try {
                if (Get-Command Get-RDMRole -ErrorAction SilentlyContinue) {
                    $roleObj = Get-RDMRole -Name $roleName -ErrorAction Stop | Select-Object -First 1
                }
            } catch { $roleObj = $null }

            if (-not $roleObj) {
                $available = @()
                try { $available = (Get-RDMRole -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Name) } catch { }
                Write-LogSimple -Message ("Role '{0}' not found. Available roles: {1}" -f $roleName, ($available -join ", ")) -Type "ERROR"
                throw "Role '$roleName' not found; cannot grant repository access."
            }

            Add-RDMRoleRepositoryAccess -Repository $Repository -Role $roleObj -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes) -ErrorAction Stop | Out-Null
            Set-RDMRole -Role $roleObj -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes) -ErrorAction Stop | Out-Null
            $resolvedRoles.Add($roleObj.Name) | Out-Null
            Write-LogSimple -Message ("Role '{0}' granted repository access." -f $roleObj.Name) -Type "DEBUG"
        }

        Write-LogSimple -Message ("Roles granted to repository '{0}': {1}" -f $Repository.Name, ($resolvedRoles -join ", ")) -Type "INFO"
    } catch {
        Write-LogSimple -Message ("Failed to assign repository roles: {0}" -f $_.Exception.Message) -Type "ERROR"
        throw
    }
}

Output:

[INFO] Connecting to https://REDACTED with application id 'REDACTED'...
[INFO] Target repository: 999999_Acme Corp
[DEBUG] Assigning roles to repository '999999_Acme Corp' (ID: REDACTED; Type: RemoteDesktopManager.PowerShellModule.PSOutputObject.PSRepositoryInfo)
[DEBUG] Resolving role 'ROLE_01'...
[DEBUG] Role 'ROLE_02' granted repository access.
[DEBUG] Resolving role 'ROLE_02'...
[DEBUG] Role 'ROLE_02' granted repository access.
[INFO] Roles granted to repository '999999_Acme Corp': ROLE_01, ROLE_02

Powershell - Unable to create repository using application identity

avatar
avatar
avatar
avatar

Hello there!

That worked, thank you!

Powershell - Unable to create repository using application identity

avatar
avatar
avatar
avatar

Hello,

Thank you for the quick response! Running New-RDMVault seems to do something, but the script does not seem to actually create a repository? It claims that the creation and import of the data (which shows a progressbar too and takes a minute) is successful, but I am unable to find the created repository in the admin view.

function New-RepositoryFromTemplate {
    param (
        [string]$NewRepositoryName,
        [string]$TemplateRepositoryName,
        [string]$TemplateExportFile 
    )
    try {
        $templateRepo = Get-RDMRepository -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $TemplateRepositoryName } | Select-Object -First 1
        if (-not $templateRepo) {
            Write-LogSimple -Message "Template repository '$TemplateRepositoryName' not found. Creating empty repository and importing cache if available." -Type "WARNING"
        }

        $newRepo = New-RDMVault -Name $NewRepositoryName -ErrorAction Stop -IsAllowedOffline $true -VaultContentType "Everything"
        if (-not $newRepo) {
            $newRepo = Get-RDMRepository -ErrorAction Stop | Where-Object { $_.Name -eq $NewRepositoryName } | Select-Object -First 1
        }
        if (-not $newRepo) { throw "Repository '$NewRepositoryName' could not be created or resolved." }
        Set-RDMCurrentRepository -Repository $newRepo -ErrorAction Stop

        if ($TemplateExportFile -and (Test-Path $TemplateExportFile)) {
            Write-LogSimple -Message "Importing template cache '$TemplateExportFile'." -Type "INFO"
            Import-RDMSession -Path $TemplateExportFile -Set -ErrorAction Stop `
                -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes) -DuplicateAction "Overwrite"
        } else {
            Write-LogSimple -Message "No template cache provided. Run single export/import flow if needed." -Type "WARNING"
        }

        Write-LogSimple -Message "Template applied to '$NewRepositoryName'." -Type "INFO"
    } catch {
        Write-LogSimple -Message "Error while cloning template: $($_.Exception.Message)" -Type "ERROR"
        $existingRepo = Get-RDMRepository -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $NewRepositoryName } | Select-Object -First 1
        if (-not $existingRepo) {
            New-RDMVault -Name $NewRepositoryName -ErrorAction Stop -IsAllowedOffline $true -VaultContentType "Everything" | Out-Null
        }
        throw
    }
}

And here how I call it:

try {
    $appId = $ScriptConfig.ApplicationId
    $appSecretPath = $ScriptConfig.ApplicationSecretFile
    if ([string]::IsNullOrWhiteSpace($appId)) {
        throw "ApplicationId must be configured."
    }
    if ([string]::IsNullOrWhiteSpace($appSecretPath) -or -not (Test-Path $appSecretPath)) {
        throw "ApplicationSecret file missing: $appSecretPath"
    }
    $appSecret = (Get-Content -Path $appSecretPath -Raw).Trim()
    if ([string]::IsNullOrWhiteSpace($appSecret)) {
        throw "ApplicationSecret file is empty: $appSecretPath"
    }

    if ($OverrideOptionFilePath) {
        $optionDir = Split-Path $OverrideOptionFilePath -Parent
        if ($optionDir -and -not (Test-Path $optionDir)) {
            New-Item -ItemType Directory -Path $optionDir -Force | Out-Null
        }
        $override = Get-RDMPowerShellOverride
        $override.OptionFilePath = $OverrideOptionFilePath
        Set-RDMPowerShellOverride
    }

    Write-LogSimple -Message "Connecting to $DvlsUrl with application id '$appId'..." -Type "INFO"

    $ds = New-RDMDataSource -DVLS -Name $ScriptConfig.DataSourceName -Server $DvlsUrl -ScriptingTenantID $appId -ScriptingApplicationPassword $appSecret -SetDatasource -WarningAction SilentlyContinue
    Set-RDMDataSource $ds
    Set-RDMCurrentDataSource $ds

    $templateCache = Get-TemplateExport -TemplateRepositoryName $ScriptConfig.TemplateRepositoryName `
        -TemplateExportPath $ScriptConfig.TemplateExportPath `
        -Force:$ScriptConfig.ForceTemplateExport

    if (-not $templateCache) { throw "Template export unavailable; aborting repository creation." }

    $newRepoName = "{0}_{1}" -f $CustomerNo.Trim(), $CustomerName.Trim()
    Write-LogSimple -Message "Target repository: $newRepoName" -Type "INFO"

    try {
        $existingRepo = Get-RDMRepository -ErrorAction Stop | Where-Object { $_.Name -eq $newRepoName } | Select-Object -First 1
    } catch {
        $existingRepo = $null
    }

    if ($existingRepo) {
        Write-LogSimple -Message "Repository '$newRepoName' already exists (ID: $($existingRepo.ID)). Skipping creation." -Type "WARNING"
        return
    }

    if (-not $PSCmdlet.ShouldProcess($newRepoName, "Create repository from template '$($ScriptConfig.TemplateRepositoryName)'")) {
        Write-LogSimple -Message "Creation of '$newRepoName' would run." -Type "WHATIF"
        return
    }

    New-RepositoryFromTemplate -NewRepositoryName $newRepoName `
        -TemplateRepositoryName $ScriptConfig.TemplateRepositoryName `
        -TemplateExportFile $templateCache

    Add-CreatedRepository -RepositoryName $newRepoName

    Write-LogSimple -Message "Repository '$newRepoName' created from template '$($ScriptConfig.TemplateRepositoryName)'." -Type "ACTION"
} catch {
    Write-LogSimple -Message "Error during repository creation: $($_.Exception.Message)" -Type "ERROR"
    Write-LogSimple -Message "Details: $($_.ToString())" -Type "ERROR"
} finally {
    Close-DSSession | Out-Null
} 

Powershell - Unable to create repository using application identity

avatar
avatar
avatar
avatar

Hello there,

I am currently trying to migrate an existing script that performs batch operations from using a username and password to using an application identity. The script should create a repository using a given name, using an existing repository as template.

Logging in has worked so far:

    $appId = $ScriptConfig.ApplicationId
    $appSecret = $ScriptConfig.ApplicationSecret
    if ([string]::IsNullOrWhiteSpace($appId) -or [string]::IsNullOrWhiteSpace($appSecret)) {
        throw "ApplicationId and ApplicationSecret must be configured."
    }

    if ($OverrideOptionFilePath) {
        $optionDir = Split-Path $OverrideOptionFilePath -Parent
        if ($optionDir -and -not (Test-Path $optionDir)) {
            New-Item -ItemType Directory -Path $optionDir -Force | Out-Null
        }
        $override = Get-RDMPowerShellOverride
        $override.OptionFilePath = $OverrideOptionFilePath
        Set-RDMPowerShellOverride
    }

    Write-LogSimple -Message "Connecting to $DvlsUrl with application id '$appId'..." -Type "INFO"

    $ds = New-RDMDataSource -DVLS -Name $ScriptConfig.DataSourceName -Server $DvlsUrl -ScriptingTenantID $appId -ScriptingApplicationPassword $appSecret -SetDatasource -WarningAction SilentlyContinue
    Set-RDMDataSource $ds
    Set-RDMCurrentDataSource $ds

Unfortunately, trying to create a repository using the same login, yields in "Session does not seem authenticated" errors.

New-DSVault -Name $NewRepositoryName -ErrorAction Stop -SecurityLevel "Standard" -IsAllowedOffline $true -AllowedRolesList ("ROLE_01", "ROLE_02")

I read in the documentation that application identities have no permissions by default, but I am unsure how I would give it permission to create the vault. Here are my system permissions:

What permissions do I need to set / grant for this to work?

Extremely poor performance when exporting / importing XML via Powershell

avatar
avatar
avatar

Hey Marc,

After executing the command and running another migration attempt, it no longer appears in the Recent Expensive Queries.

We are okay with the performance now, but have gotten reports that 1-2 hours after starting to import (total runtime is 4-5 hours at this point) users sometimes don't see any repositories. I assume the server is too busy processing the imports that user requests time out or something similar. The issue resolved itself after 10 minutes (we did not stop importing).

Do we need to add pauses between each import?

Extremely poor performance when exporting / importing XML via Powershell

avatar
avatar
avatar

Hey Marc,

> Out of curiosity, if you use the export feature in RDM to export your template vault as a .rdm file, do you see the query "SELECT * FROM dbo.Connections WHERE Version > @Version" occurring just as often?

Yes.

> In their case, it was mainly due to the high number of concurrent users on the solution

Sounds like this could also be the case for us. We also have a high number of concurrent users.

fyi, I was able to cut down the import time from 15 minutes to 5 minutes, by chunking the exported .rdm file in such a way, that I am importing empty folders first and then only the connections. My guess is that switching between those operations is time-intensive when doing a regular import, which is why it takes longer.

Extremely poor performance when exporting / importing XML via Powershell

avatar
avatar
avatar

Hello there,

We are currently in the process of migration our mono-repo into smaller repos on a per-customer basis. For that we would like to use a template repo we have created that has roughly 350 pre-created items.

I use

Export-RDMSession -XML -Sessions $templateEntries -IncludeCredentials -IncludeAttachements -IncludeDocumentation `

-Path $TemplateExportPath -ErrorAction Stop -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes)

to export the template, and

Import-RDMSession -Path $TemplateExportFile -SetSession -ErrorAction Stop `

-ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes) -DuplicateAction "Overwrite"

to import it, but noticed that this takes roughly 15 minutes to complete. We have looked into every VM involved with the setup of DLVS, but the only anomaly we could find is this on the SQL server:

This query is called 150-500 times per minute, with 500k reads each, while the export is running.

We are already investigating different approaches (i.e. caching the exported template and re-use it), but were unable to yield better performance.

Version: 2025.2.28.0

Attachments inside RDM export not being imported

avatar
avatar
avatar
avatar

Hello there,

We are currently trying to migrate from a monolithic repository (which contains a folder for each client) to a structure that is one repository per client.

For that I would like to export all folders as RDM files, create a new repository and then import the contents back into the new repository.

Here is the code I am trying to use:

try {

# Create temp file for export

$tempExportFile = "C:\Dev\_temp\RDM\" + $clientFolder.Name + ".rdm"

# Export data

Export-RDMSession -XML -Sessions $clientEntries -IncludeCredentials -IncludeAttachements -IncludeDocumentation -Path $tempExportFile -ErrorAction Stop -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes)

Write-LogSimple -Message "Data exported to: $tempExportFile" -Type "INFO"

# change repo

Set-RDMCurrentRepository -Repository $targetRepo -ErrorAction Stop

# import into new repo

Import-RDMSession -Path $tempExportFile -ErrorAction Stop -ForcePromptAnswer ([System.Windows.Forms.DialogResult]::Yes) -DuplicateAction "Ignore" | Set-RDMSession

Write-LogSimple -Message "success" -Type "ACTION"

} catch {

Write-LogSimple -Message "error '$($clientFolder.Name)': $($_.Exception.Message)" -Type "ERROR"

# delete temp file

if (Test-Path $tempExportFile) {

Remove-Item -Path $tempExportFile -Force -ErrorAction SilentlyContinue

}

}

For the Import-RDMSession command I tried using the -SetSession parameter too, with the same result. The entries (i.e. credentials) and folders are present in the new repository, while the attachments are not.

Importing the exported .rdm file using the desktop application will import the attachments successfully.

I tried placing the attachment into the root, on folder level and on a credential. None of them are imported. The export seemingly captures them indicated by the file size (38 MB), which also gets larger the more attachments I place.

I tried this with Devolutions.PowerShell 2025.2.0, 2025.1.5 and 2025.1.4, with no success.

Please advise.

Sincerely,

Kia Armani

1 - 10 of 10 items