Modifying .rtsz file directly

Hi!

I’m a new Royal TS user. So far I like it a lot, but I need to input pretty big number or Telnet/SSH objects in a tree (few hundreds total). I’m fine with bulk add when it comes to have same connection settings but different IP address.

I have, however, couple terminal servers where the IP remains the same, but 20-40 different port numbers point to different devices I want to have connection to. Bulk add doesn’t seem to recognize IP:port format.

I tried to export CSV to have an easily editable structure with no clicks in between, but exporting all parameters only gives me object names.

I thought now of editing .rtsz file directly but can really achieve my goal this way? I’m concerned about making up the component.

Cheers!

Hi and welcome to the Royal Family!

CSV import is probably the easiest way. The imported objects are based on the default settings so you only need the fields which need to be customized (like name, IP, port) and afterwards you can also utilize bulk-edit to tweak a group of connections afterwards. If you need a folder structure, there’s a sample script:

This brings me to scripting in general. You can use PowerShell to create or update documents:

Let me know if this helps.

Regards,
Stefan

1 Like

Hi Stefan,

Thank you!.

I need to process a CSV that will consist of a folder path, object type, destination IP/port.

I just have to play with it a little. Had to harness Python and VBA for my job, now it’s time for PS. :wink: But it doesn’t seem difficult to adjust the source script.

If I can get direct VM GUI access somehow in Royal TS, that’s 100% of what I need.

Kind regards,
Tomasz

Sounds good. Let me know if you have any further questions.

1 Like

I made some quick and dirty modification of the script you referenced.

The script is supposed to support SSH, Telnet, Web, VMware, SFTP.

Currently I tested that on a .csv with 200 items, it will end up at around 500. Didn’t test SFTP part yet. Going to add RDP option.

I will still have to work on combining this with predefined credential set and some mapping of them in the CSV.

Sample input CSV:

Folder,Name,URI,Port,ObjType,CredUser,CredPass
Connections/Labs/General,vSphere,10.10.0.100,RoyalVMwareConnection,someusername,somepassword
Connections/Labs/Lab1,Core-A,10.1.1.200,
Connections/Labs/Lab1/Switches,1-Switch-A,10.1.1.11,
Connections/Labs/Lab3/Web Servers,Svr1,https://10.1.2.3:9443,RoyalWebConnection,

If ObjType is blank, SSH/Telnet is assumed.

For Port:

  • If SSH/Telnet, and Port is blank → Telnet w/ port 23
  • If SSH/Telnet, and Port is 22 → SSH w/ port 22
  • If SSH/Telnet, and Port is custom → Telnet w/ custom port no.
Import-Module RoyalDocument.PowerShell
  
function CreateRoyalFolderHierarchy()
{
  param(
    [string]$folderStructure,
    [string]$splitter,
    $Folder
  )
  $currentFolder = $Folder

  $folderStructure -split $splitter | %{
    $folder = $_
    $existingFolder = Get-RoyalObject -Folder $currentFolder -Name $folder -Type RoyalFolder
    if($existingFolder)
    {
      Write-Verbose "Folder $folder already exists - using it"
      $currentFolder = $existingFolder
    }
    else
    {
      Write-Verbose "Folder $folder does not exist - creating it"
      $newFolder= New-RoyalObject -Folder $currentFolder -Name $folder -Type RoyalFolder
      $currentFolder  = $newFolder
    }
  }
  return $currentFolder
}

$fileName = "test.rtsz" #relative to the current file-system directory
#if(Test-Path $fileName) {Remove-Item $fileName}

$store = New-RoyalStore -UserName "PowerShellUser"
$doc = New-RoyalDocument -Store $store -Name "Powershell import from CSV" -FileName $fileName

Import-CSV -Path test.csv | %{

  $server = $_
  Write-Host "Importing $($server.Name)"

  $lastFolder = CreateRoyalFolderHierarchy -folderStructure $server.Folder -Splitter  "\/" -Folder $doc
  
  if ([string]::IsNullOrWhiteSpace($server.ObjType)) {
    $newConnection = New-RoyalObject -Folder $lastFolder -Type RoyalSSHConnection -Name $server.Name
	if ([string]::IsNullOrWhiteSpace($server.Port)) {
		$newConnection.ConnectionType = "telnet;Telnet"
		$newConnection.Port = "23"
	}
	else {
		switch($server.Port) {
			"22" {
				$newConnection.ConnectionType = "ssh"
				$newConnection.Port = "22"
			}
			default {
				$newConnection.ConnectionType = "telnet;Telnet"
				$newConnection.Port = $server.Port
			}
		}
	}
  }
  else {
    switch($server.ObjType) {
		"RoyalWebConnection" {
		    $newConnection = New-RoyalObject -Folder $lastFolder -Type RoyalWebConnection -Name $server.Name
		}
		"RoyalVMwareConnection" {
			$newConnection = New-RoyalObject -Folder $lastFolder -Type RoyalVMwareConnection -Name $server.Name
			$newConnection.CredentialMode = 2
			$newConnection.CredentialUsername = $server.CredUser
			$newConnection.CredentialPassword = $server.CredPass
		}
		"RoyalFileTransferConnection" {
			$newConnection = New-RoyalObject -Folder $lastFolder -Type RoyalFileTransferConnection -Name $server.Name
			$newConnection.Protocol = 3
			$newConnection.CredentialUsername = $server.CredUser
			$newConnection.CredentialPassword = $server.CredPass
		}
		"RoyalSSHConnection" {
			$newConnection = New-RoyalObject -Folder $lastFolder -Type RoyalSSHConnection -Name $server.Name
			if ([string]::IsNullOrWhiteSpace($server.Port)) {
				$newConnection.ConnectionType = "telnet;Telnet"
				$newConnection.Port = "23"
			}
			else {
				switch($server.Port) {
					"22" {
						$newConnection.ConnectionType = "ssh"
						$newConnection.Port = "22"
					}
					default {
						$newConnection.ConnectionType = "telnet;Telnet"
						$newConnection.Port = $server.Port
					}
				}
			}
		}
	}
  }
  $newConnection.URI = $server.URI
}
Out-RoyalDocument -Document $doc -FileName $fileName

Any advice on how this can be improved is more than welcome.

Kind regards,
Tomasz

1 Like