I got a lot of feedback lately, that Royal TS needs an import functionality. I completely agree, but I soon realized, that almost everyone has different requirements. So thinking through all possibilities and providing a powerful UI which can handle all different requirements would be very time consuming.
So I thought, providing a sample script which shows how this can be done should get you started. I guess most Royal TS users are IT professionals and shouldn't have much trouble tweaking and adjusting the script. But keep in mind that this is a sample which handles the most common parameters and depending on the format of your CSV you need to change the field names in the script to match those from the CSV, add more fields, remove some fields, etc.
So here we go:
Save the script to C:\Create-RoyalTSFile.ps1
Save a CSV file to C:\myconnections.csv
Use the script like: C:\Create-RoyalTSFile.ps1 C:\myconnections.csv C:\mynewroyaltsfile.rts
When the script is finished, you should be able to open the "mynewroyaltsfile.rts" with the password "ScriptTemplatePassword" (without the quotes!)
After you opened the .rts file, change the password and/or protection level of the document, make some individual changes or bulk-changes and save it.
Copy the following code into a new text file named: "Create-RoyalTSFile.ps1":
#============================================================================
#
# Create-RoyalTSFile.ps1 [csv-file]
#
#============================================================================
# This is a sample PowerShell script which takes a comma-separated file and
# builds a Royal TS file from its content.
#
# The csv file must have the following format:
# ComputerName,Description,UserName,Domain,Password
# MailServer1,Exchange 2007,jlocke,dharma,4815162342
# MailServer2,Exchange 2007,jlocke,dharma,4815162342
#
# If your file format looks differen you need to adjust the script
#
# ----------------------------------------------------------------------------
param
(
[string]$csvFileName = $(throw write-Host "You need to provide a csv file name."),
[string]$rtsFileName = $(throw write-Host "You need to provide a rts file name.")
)
# load application to use the encryption method
# =============================================
[Reflection.Assembly]::LoadFrom("$Env:ProgramFiles (x86)\code4ward\Royal TS\RtsApp.exe")
# .rts file is password protected "ScriptTemplatePassword"
# .rts file building blocks
# =========================
# .rts file document begin
# ------------------------
function Get-DocumentBeginBlock
{
$DocumentBeginBlock = '<?xml version="1.0" encoding="utf-8"?>
<RTSDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Categories>'
return $DocumentBeginBlock
}
# .rts file document end block
# ----------------------------
function Get-DocumentEndBlock([string]$DocumentName, [string]$FileName)
{
$DocumentEndBlock = " </Categories>
<DocumentName>$DocumentName</DocumentName>
<FileName>$FileName</FileName>
<Signature>30C9D2AB4461FB1DB9BADD99FBF8496F5CC960F5490FD0EF725EE626BFCFE44AF88AF7E63A76CAF02AE36268315564C2C77FA819A323815EA2F9095CC843E660</Signature>
<SL2>30C9D2AB4461FB1DB9BADD99FBF8496F5CC960F5490FD0EF725EE626BFCFE44AF88AF7E63A76CAF02AE36268315564C2C77FA819A323815EA2F9095CC843E660</SL2>
<Level>1</Level>
<CL2>dIqAMreTI2lYGRVQrApJSAinrW2DOpiI</CL2>
<DocVersion>2</DocVersion>
</RTSDocument>"
return $DocumentEndBlock
}
# .rts file category begin block
# ------------------------------
function Get-CategoryBeginBlock([string] $CategoryName)
{
$CategoryBeginBlock = " <RTSCategory>
<CategoryName>$CategoryName</CategoryName>
<IsExpanded>false</IsExpanded>
<Connections>
"
return $CategoryBeginBlock
}
# .rts file category end block
# ----------------------------
function Get-CategoryEndBlock
{
$CategoryEndBlock = " </Connections>
</RTSCategory>"
return $CategoryEndBlock
}
# .rts file connection block
# --------------------------
function Get-ConnectionBlock
{
param
(
[string]$ConnectionName = $(throw write-Host "You need to provide a unique connection name."),
[string]$HostName = $ConnectionName,
[string]$Description = "",
[string]$UserName = "",
[string]$Domain = "",
[string]$Password = "",
[bool]$SavePassword = $false
)
# check if we can set auto logon (only possible if user, domain and password is set
if (($UserName -ne "") -and ($Domain -ne "") -and ($Password -ne "") -and ($SavePassword))
{
$SavePasswordString = "true"
}
else
{
$SavePasswordString = "false"
}
# check if a password should be encrypted
if ($Password -ne "")
{
$EncryptedPassword = [code4ward.RoyalTS.SecurityExtensions]::Encrypt($Password, "ScriptTemplatePassword")
}
else
{
$EncryptedPassword = ""
}
# build a connection
$ConnectionBlock = " <RTSConnection>
<ConnectionName>$ConnectionName</ConnectionName>
<Host>$HostName</Host>
<Description>$Description</Description>
<User>$UserName</User>
<Domain>$Domain</Domain>
<SavedPassword>$EncryptedPassword</SavedPassword>
<SavePassword>$SavePasswordString</SavePassword>
<ColorDepth>BPP24_TrueColor</ColorDepth>
<DesktopWidth>640</DesktopWidth>
<DesktopHeight>480</DesktopHeight>
<AutoExpand>true</AutoExpand>
<ExternalWindow>false</ExternalWindow>
<MinimizaMainWindow>false</MinimizaMainWindow>
<SmartSize>true</SmartSize>
<BitmapCaching>true</BitmapCaching>
<RedirectDisks>true</RedirectDisks>
<RedirectPrinters>true</RedirectPrinters>
<RedirectPorts>true</RedirectPorts>
<RedirectSmartCard>true</RedirectSmartCard>
<ConnectToConsole>true</ConnectToConsole>
<EnableWindowsKeys>true</EnableWindowsKeys>
<AllowBackgroundInput>true</AllowBackgroundInput>
<AutoReconnect>true</AutoReconnect>
<EnableTSGateway>false</EnableTSGateway>
<TSGatewayServer></TSGatewayServer>
<RdpPort>3389</RdpPort>
<AllowWallpaper>true</AllowWallpaper>
<AllowThemes>true</AllowThemes>
<AudioSetting>PlayOnClient</AudioSetting>
<PropertySplitterPosition>177</PropertySplitterPosition>
<HideProperties>false</HideProperties>
<HideTSCNavigation>true</HideTSCNavigation>
<Top>-1</Top>
<Left>-1</Left>
<Screen />
</RTSConnection>
"
return $ConnectionBlock
}
# ==========================================================================
# Now let's begin to build the .rts file
# ==========================================================================
# start with the document
$RTSFile = Get-DocumentBeginBlock
# now we create one category where we place all connections
$RTSFile += Get-CategoryBeginBlock "My Test Category"
# here we open the csv file and create a connection for every line
Import-Csv $csvFileName | ForEach-Object { $RTSFile += Get-ConnectionBlock $_.ComputerName $_.ComputerName $_.Description $_.UserName $_.Domain $_.Password $true }
# now let's finish the document
$RTSFile += Get-CategoryEndBlock
$RTSFile += Get-DocumentEndBlock "MyTestDocument" $rtsFileName
# write the .rts file to the file system
$RTSFile | Out-File -filepath $rtsFileName -NoClobber
Here the sample CSV file:
ComputerName,Description,UserName,Domain,Password
MailServer1,Exchange 2007,jlocke,dharma,4815162342
MailServer2,Exchange 2007,jlocke,dharma,4815162342
I hope I could give you a headstart with that script. Of course you could easily extend the script to create categories according to a field in the csv and assign connections to them.
You could also make it more flexible to control much more settings (like redirection, color depth, etc) by defining them in the csv. In any case, don't be shy and post your custom scripts to this thread.
cheers
Stefan