When managing Windows servers there is no way around PowerShell. So it was only logical that one of the most requested features was to fully integrate PowerShell in our products.
Note: This feature is included in the current beta releases of Royal TS and Royal Server (Royal TSX is coming soon!).
By executing PowerShell scripts on remote machines you can achieve virtually everything an IT Pro dreams of:
Creating a new PowerShell connection is straight forward: just add it by using the context menu:
Enter a Display Name and a Computer Name (as usually, this can be a list of Computers):
Paste it in the Script tab:
Note: Always take care which scripts you execute from the Internet.
Note: This script does not work if you have a different operating system language than English because of the hard-coded group name “Administrators”
Note: I modified the script in the way that it returns a PowerShell object instead of strings
Now, this script contains a function, but no output yet. Since we actually want to get back the members we have to add the following code at the end:
get-localadmin -strcomputer localhost
In the Display Options you can specify if the output of your script should be shown as Text (as in the PowerShell console) or as a Grid.
Note: The checkbox Show Script Panel displays the script directly above the script output when you connect which enables you to easily adapt the script and see the changes immediately.
The Text tab in the Display Options settings page allow you to configure the Font, Font Size etc as you can configure it in your normal PowerShell console.
If you work with remote machines, specify a Credential that has the necessary rights.
The Royal Server settings page allows you to specify, if you want to execute the PowerShell script by using Royal Server or Direct Connect (No Royal Server).
As a result you get all logged in users from the specified hosts:
If you took a close look, we had to add the following line to the end of the script:
get-localadmin -strcomputer localhost
The computer is “localhost” since the PowerShell connection executes the script for each host that is entered in the Computer Name by using PowerShell Remoting. If you enter multiple hosts, the script is executed on multiple machines:
Note: See the different hosts in the __ComputerName column which was populated from the Computer Name property from the Connection.
But what if you actually want to pass in parameters to the Script? Additionally these parameters should be populated by information already stored in some Royal Object.
Lets assume, you want to specify the Administrators groups name in the CustomField1 in Royal TS and push it to the script when it executes.
1. Specify the name in the CustomField1:
2. Adapt the script to work with Parameters
Every script needs to be prepared to work with Parameters. This is a block at the beginning of the script that looks like this:
Params ( $param1 )
Adapt the script to use the newly introduced parameter:
Note: The script has been changed to use the $AdminGroupName variable
3. Define the parameters in the Parameters Tab
Specify the parameter by referencing the CustomField1 variable.
Note: The Test Value can be used for specifying static values for testing the script in the Test tab.
For testing purposes you can specify test-values and execute the Script in the Test tab to see if it works as expected (the output when testing is always Text)
When you still develop a script, its inconvenient to always reopen the properties of the PowerShell Connection if you want to change the script. As a shortcut, you can use our Script Panel and edit your script and Refresh the output to see the results.
Rendering the output of the script as a Grid only works if the script actually returns objects. But if the output is just plain text chose Text as Default Output in the Display Options settings page.
Consider the following script:
With Default Output set to Text: