With Royal TS V3.1 we introduced a new PowerShell connection type which allows you to run any PowerShell script and display the results in a grid (for object data) or as text (like the console). In this quick tutorial I want to show how to pass on the connection credentials as parameters to be used in the script.

All you need in the script is a param script block where you define which parameters the script expects. In our example, the $usr and the $pwd, both string values are expected as script parameters:


Note: only named parameters are supported. Indexed parameters are not supported.

In the Parameters tab we can now map those with replacement tokens from Royal TS or any static value:


As Parameter Name, enter the name from the param script block without the $ character. As value, either enter just a static text or use a replacement token (like $EffectiveUsername$, $EffectivePassword$, $CustomField1$, etc.). The fly-out button shows a list of all available replacement tokens. Add all mappings you need to the list.

In our example, we will also configure Royal TS to prompt for a credential by setting up the Credentials configuration to Specify a credential by name and using the ? character as credential name – as described here. Once all is set up, you will get a credential prompt when you connect:


The sample script from above will just output whatever credentials we entered:


As you can see, the parameter mapping allows you to not only use credentials or values from the connection object, it also ensures that the script can be used *as is* without any modifications outside of Royal TS. There’s no magic, only standards based named parameters used here.

Previous Post Next Post