Some time ago, we released a new PowerShell module together with Royal TS that enables you to manage Royal TS documents via PowerShell (check out the awesome PowerShell Magazine introduction article about this module by Jan Egil Ring). Now we follow up with commandlets to work with Royal Server.
In general, the Royal Server cmdlets let you work with Royal Server without having Royal TS running. All Management Connections of Royal Server can be used directly, e.g. you can achieve these scenarios easily in a PowerShell console:
While it’s cool to work with Royal Server from Royal TS in some scenarios (think scripting and automation), you can achieve most of the functionality with built-in PowerShell modules – so why should you go to for the Royal Server PowerShell commandlets?
Note: Right now, the Royal Server commandlets are in beta and the interface of the commandlets might change in the future. But we would be very interested in your thoughts on this way to use Royal Server. Please use our support portal for features suggestions or reporting bugs.
If you install Royal Server, you will find a RoyalServer.PowerShell.dll in the installation directory. Import this module as you would usually do:
$rsmodule = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath 'RoyalServer\RoyalServer.PowerShell.dll'
Import-Module $rsmodule
Before we begin, we have to specify the Royal Server to which we want to talk:
$cred = Get-Credential $config = New-RoyalServerConfig -Credential $cred -Host 127.0.0.1 -UseSSL $true -Port 54899
Now we are ready to issue our first command: lets fetch the last 10 EventLog entries:
Invoke-RoyalServerCommand -ModuleID EventLog -Command "GetEntries" -RoyalServerConfig $config -DestinationHost "127.0.0.1" -MaxRecords 10 | Format-Table
Now, we can get a bit more sophisticated with our query. The next examples is using query arguments (and specifies only Log entries from the Application log):
$p = @{"WQLWhereClause" = "LogFile='Application'"}
Invoke-RoyalServerCommand -ModuleID EventLog -Command "GetEntries" -Arguments $p -RoyalServerConfig $config -DestinationHost "127.0.0.1" -MaxRecords 10 | Format-Table
The Module-Parameter is using the Enum “ModuleNames” which can be specified like this:
$module = [RoyalServer.PowerShell.ModuleNames]::TerminalServices
This enables the PowerShell console to offer tab-completion in your console. But how can we find out which values are allowed for the parameters -Command and even -Arguments?
Get-RoyalServerModule shows available modules:
Get-RoyalServerModule -RoyalServerConfig $config
Get-RoyalServerModuleCommand shows the available commands:
Get-RoyalServerModuleCommand -RoyalServerConfig $config -ModuleID EventLog
Get-RoyalServerModuleCommandParameter shows available parameters:
Get-RoyalServerModuleCommandParameter -RoyalServerConfig $config -ModuleID EventLog -Command "GetEntries" | Format-List
Remark: Note the ” | Format-List” at the end, which produces an output that is better readable 😉
The commandlets New-RoyalServerConfig and Invoke-RoyalServerCommand need (if Royal Server is properly configured) some credentials to work. There are two ways to provide this information:
$secpasswd = ConvertTo-SecureString "<your-secure-password>" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("<username", $secpasswd)
Note: We do not recommend this for production usage.
PS: It is not required that you have the same color configuration in your PowerShell console as I have 😉