This is a sample PowerShell script that demonstrates how to create Royal TS/X documents based on the content of a CSV file.
Remark: You need to import the Royal TS PowerShell module to get this running (assuming you have installed Royal TS to the default location):
Install-Module -Name RoyalDocument.PowerShell -Scope CurrentUser Import-Module -Name 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 = "outputcsv.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 servers.csv | %{ $server = $_ Write-Host "Importing $($server.Name)" $lastFolder = CreateRoyalFolderHierarchy -folderStructure $server.Folder -Splitter "\/" -Folder $doc $newConnection = New-RoyalObject -Folder $lastFolder -Type RoyalRDSConnection -Name $server.Name $newConnection.URI = $server.URI } Out-RoyalDocument -Document $doc -FileName $fileName
The above script processes a CSV file with the following structure:
Folder,Name,URI lab/dmz,server1,127.0.0.1 lab/int,server2,127.0.0.2 lab/int,server3,127.0.0.3