Blogging about Royal TS/X, Royal Server and Royal Passwords

New Feature: PowerShell Connection

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!).

 

Use Cases

By executing PowerShell scripts on remote machines you can achieve virtually everything an IT Pro dreams of:

  • Manage User Accounts (resetting the password, disabling/enabling them, unlocking them etc)
  • Installing Windows Features
  • Working with specialised PowerShell commands for Exchange, Sharepoint etc
  • Searching for patterns in SQL Databases
  • Work with DSC (Desired State Configuration) commands
  • and so much more …

 

Creating a PowerShell connection

Creating a new PowerShell connection is straight forward: just add it by using the context menu:

2015-05-21 11_51_55-

Enter a Display Name and a Computer Name (as usually, this can be a list of Computers):

2015-05-21 16_27_10-Add PowerShell Connection

Lets assume, we want to display all Administrators on a server. The Microsoft TechNet Script Center already has a script that does this. You can find it here.

Paste it in the Script tab:

2015-05-21 16_39_21-Edit Properties_ Get members of Administrator group

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.

2015-05-21 12_56_32-Add PowerShell Connection

 

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.

2015-05-21 12_57_02-Add PowerShell Connection

 

If you work with remote machines, specify a Credential that has the necessary rights.

2015-05-21 13_07_13-Add PowerShell Connection

 

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).

2015-05-21 12_57_31-Add PowerShell Connection

 

As a result you get all logged in users from the specified hosts:

2015-05-21 16_40_56-Get members of Administrator group

 

Executing on multiple Servers

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:

2015-05-21 16_38_59-Get members of Administrator group

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.

 

Working with Parameters

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:

2015-05-21 16_43_52-Edit Properties_ Get members of Administrator group

 

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:

 


2015-05-21 17_00_07-Edit Properties_ Get members of Administrator group

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.

2015-05-21 16_48_50-Edit Properties_ Get members of Administrator group

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)

 

Developing a Script

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.

2015-05-21 17_05_44-

 

Using the Text output

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:

2015-05-21 17_57_38-Edit Properties_ Restart Printer Spooler

 

With Default Output set to Text:

2015-05-21 17_57_52-

 



4 views shared on this article. Join in...

  1. Ryan says:

    Is it possible to have the task ask for a parameter? For instance a script that asks for a username, then is executed.

    So the flow would be
    1. Run the Script from Royal TS
    2. Script asks for username
    3. Script executes “get-aduser -identity $username$ “

  2. Felix Deimel says:

    Hi Ryan,

    this feature is already on our roadmap for the next major release.

    regards,
    felix



Pings to this post

  1. […] Read more about the new PowerShell connection in Royal TS and how to integrate it with Royal Server here. […]

  2. […] Royal TS V3.1 we introduced a new PowerShell connection type which allows you to run any PowerShell script (locally or remotely using PS Remoting or Royal […]


You must be logged in to post a comment.