Dynamically populate Custom Tool fields with PowerShell

When delegating administrative tasks using Custom Tools, you may need to query or modify information before the web form is presented to the user. The possibilities are limitless, but some examples of this might be:

Getting a list of available datastores before provisioning a VM

Enumerating a filtered list of shares on a remote host to allow a Help Desk person to grant access

Allow an application support tech to run more specific troubleshooting tools based on quick preliminary, real-time analysis

Show a list of tickets for a server from an external ticketing system, then force a valid ticket before performing an API action

Example with code

In the following example, we need a tool that will allow a user to see a real-time list of Windows services on a remote computer and then choose to view, start or stop one of those services. We’ll need to do the following:

Create the custom fields needed to capture user input

Create a preprocessor custom tool to query Windows services and dynamically populate a custom field

Create the main custom tool that a delegated user will run to manage Windows services

First, create two ListBox custom fields called ServiceAction and ServiceListBox by going to Settings > Custom fields > New

This is the main custom tool that a delegated user will run. Add it to System Frontier by going to Tools > Create Tool. Name it “Dynamic Field Sample” and choose a meaningful category, but not Preprocessor.

Click on the Modify button under User Input Fields, select the two custom fields you added earlier, click Add then Done to return to the tool configuration screen.

Modify your Arguments section to capture the current hostname and user input fields in order to pass their values to the command-line of this tool.

Under Preprocessor, choose the “Preprocessor Sample” script that you added earlier. Only custom tools with a category of Preprocessor will appear in this list.

When you’re done, it should look similar to the screenshot below.

Let’s test it

Now, search for a computer in System Frontier, click on it and then click on the Tools tab. You should see the new Dynamic Field Sample tool. Click Open. Here’s what’s happening behind the scenes:

The main tool calls the preprocessor tool, passing it information it needs like the list of target hostnames and custom fields.

The preprocessor script performs it’s magic, updates all the data that was passed in a returns it to the main tool.

The main tool then uses relevant data that was returned to populate custom fields before the web form is presented to the user.

Notice the ServiceListBox field has the list of all Windows services that were returned by the preprocessor tool!

The user makes choices or adds information, if needed and runs the tool.

All values are passed to the command-line of your script and run under elevated credentials.

In this example, starting the SNMP Trap service successfully should return output to the web console like so:

If designed correctly, preprocessor scripts and custom fields can be reusable and modular. All this without the need to write HTML or wire up Windows forms controls.

Don’t forget, you can run custom tools on a list of hostnames, as long as they exist in SF, and the tool will automatically take advantage of multi-threading and parallel execution without additional code.

Additional Info

Hashtable keys should be strings, so if you are pulling data from somewhere and the keys are numeric (int from SQL, etc.) be sure to convert them to strings before updating the data bus.