How export RDM config ? (.cfg)

How export RDM config ? (.cfg)

avatar

Hi !

First, I want to give you a gift :

tasks:
  - name: Ensure the required NuGet package provider ve$srsion is installed
    ansible.windows.win_shell: Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force
  - win_chocolatey:
      name: 
      - sql-server-express
      - rdm
    become: true
    become_method: runas
    become_user: "{{ ansible_user }}"
  - community.windows.win_psmodule:
      name: RemoteDesktopManager
      state: latest
  - name: Configure SQL
    ansible.windows.win_shell: |
      Invoke-Sqlcmd -ServerInstance "{{ db_instance }}" -Database Master -Query "sp_configure 'Remote access', 1 ; reconfigure"
      $s = new-object('Microsoft.SqlServer.Management.Smo.Server') '{{ db_instance }}'
      $s.Settings.LoginMode = [Microsoft.SqlServer.Management.SMO.ServerLoginMode]::Mixed
      $s.Alter()
      Restart-Service -Name 'MSSQL$SQLEXPRESS'
      Invoke-Sqlcmd -ServerInstance "{{ db_instance }}" -Database Master -Query "CREATE LOGIN [{{ rdm_dblogin }}] WITH PASSWORD = '{{ rdm_dbpass }}'"
      Invoke-Sqlcmd -ServerInstance "{{ db_instance }}" -Database Master -Query "CREATE USER [{{ rdm_dblogin }}] FOR LOGIN [{{ rdm_dblogin }}] WITH DEFAULT_SCHEMA=[dbo]"
      Invoke-Sqlcmd -ServerInstance "{{ db_instance }}" -Database Master -Query "GRANT ALTER ANY USER TO [{{ rdm_dblogin }}] WITH GRANT OPTION AS [dbo];"
      Invoke-Sqlcmd -ServerInstance "{{ db_instance }}" -Database Master -Query "GRANT CONNECT TO [{{ rdm_dblogin }}] AS [dbo];"
      Invoke-Sqlcmd -ServerInstance "{{ db_instance }}" -Database Master -Query "GRANT CREATE ANY DATABASE TO [{{ rdm_dblogin }}]"
  - name: Configure RDM
    ansible.windows.win_shell: |
      $cd = ConvertTo-SecureString "{{ rdm_dbpass }}" -AsPlainText -Force
      $reg = Get-RDMRegistrationInfo
      $reg.Name = '{{ rdm_regname }}'
      $reg.Email = '{{ rdm_regmail }}'
      $reg.Serial = '{{ rdm_regserial }}'
      Set-RDMRegistrationInfo $reg
      $d = New-RDMDataSource -Database "RemoteDesktopManager" -Name "{{ rdm_dsname }}"  -SQLServer -Password $cd -Server "{{ db_instance }}"  -Username {{ rdm_dblogin }} 
      Invoke-RDMCreateDataSourceDatabase $d
      Set-RDMDataSource $d
      Set-RDMCurrentDataSource $d
      Get-RDMDataSource | Where-Object -FilterScript {$_.Name -ne "{{ rdm_dsname }}"} | Remove-RDMDataSource
      Invoke-Sqlcmd -ServerInstance "{{ db_instance }}" -Database Master -Query "REVOKE CREATE ANY DATABASE TO [{{ rdm_dblogin }}]"
      $d = Get-RDMDataSource
      $u = New-RDMUser -Administrator -Login "{{ rdm_adminuser }}" -AuthenticationType Builtin -Email "{{ rdm_adminmail }}" -Password $cd 
      $u.FirstName = "{{ rdm_adminfname }}"
      $u.LastName = "{{ rdm_adminlname }}"
      $u.UserInfo.UserAccount.UserMustChangePasswordAtNextLogon = $True
      set-rdmUser $u
      Set-RDMDatasourceProperty -DataSource $d -Property UseDBLogin -Value $True
      Set-RDMDatasourceProperty -DataSource $d -Property LoginMode -Value "Custom"
      Set-RDMDatasourceProperty -DataSource $d -Property DBLoginUserName -Value "{{ rdm_dblogin }}"
      Set-RDMDatasourceProperty -DataSource $d -Property DBLoginPassword -Value "{{ rdm_dbpass }}"
      Set-RDMDatasourceProperty -DataSource $d -Property UserNameEditable -Value $True
      Set-RDMDatasourceProperty -DataSource $d -Property User -Value "%USERNAME%"
      Set-RDMDatasourceProperty -DataSource $d -Property Password -Value ""
      Set-RDMDataSource $d
      Set-RDMCurrentDataSource $d

A full Ansible playbook to :

  • Install sql + RDM
  • Configure SQL access
  • Configure RDM for SQL datasource with custom login (because Integrated Security is not really secure)


But. Something is missing. I need to export a .cfg as the default.cfg. (multi users support)
In the UI, it's in "Options -> Export Options -> Export". But I don't find how to do this in Powershell
And, how can I hide the registration serial to no-Administrator User ? (in UI + Powershell)

Thanks you !

All Comments (3)

avatar

Hi,

Thank you for the script. I'm sure it will be useful for other users.

There is no way to export the cfg file using PowerShell by design.
Each platform has a slightly different cfg files. Loading them is ok as unknown settings are simply ignored.
To prevent data loss, PowerShell has no way to modify or save the cfg file.

There's an option in Options -> Security called Hide local registration information that can be used.
You could also disable the Registration menu button through a policy in your data source.

Regards

Jonathan Lafontaine

avatar

I don't understand why. If a export button exists, the code already exists. You just need to write de powershell function.
I make a diff between the UI export function and the orignal cfg. There are 2 properties: OptionSensitivePacked and OptionEncryptionPacked on the exported cfg. No way to get these options with powershell to write my default.cfg ?

avatar

Hi,

As I said, PowerShell currently doesn't export or save RemoteDesktopManager.cfg to prevent data loss since each RDM platform has its unique cfg file and there is no way for PowerShell to be fully compatible with each.
That being said, since you are only looking for specific properties that are shared across all version of RDM, I'll look into an export function.

Regards

Jonathan Lafontaine