user

How to Run Parameterized PowerShell Scripts with Otter

Introduction

Crista Perlton

Crista Perlton


LATEST POSTS

How Licenses Work with Chocolately 22nd March, 2024

How to Handle npm Dependencies with Lock Files 16th January, 2024

PowerShell

How to Run Parameterized PowerShell Scripts with Otter

Posted on .

Running PowerShell scripts is easy if you’re a PowerShell guru. But what if you need non-experts to run your scripts? Using Otter to add a graphical user interface (GUI) to PowerShell makes your PowerShell scripts more accessible to more people on your team.

Otter automatically generates a UI around your PowerShell scripts, enabling those who are less comfortable or familiar with PowerShell to run scripts without expert intervention. Here’s how.

How to Use Otter to Run Parameterized PowerShell Scripts 

Step 1: Install Otter

There are a lot of installation options for Otter, but the easiest is the Inedo Hub on Windows. After the download and installation (which takes just a few minutes), you can get right to work or take a few minutes to run the demo steps and familiarize yourself with the software.

Step 2: Add Scripts to Otter 

To add your PowerShell script to Otter, navigate to Scripts > Create Script and select “PowerShell” from the list of available types. (You can also configure a raft if you want Otter to read your scripts from a Git repository, though this is more complicated.)

Step 3: Create a Job Template

You don’t have to do it this way, but we recommend job templates because they enable self-service with safety by defining usage restrictions. For example, you can restrict which servers a script may run on. 

Job templates also let you define variable prompts.

Step 4: Create Variable Prompts

Otter can also generate an input prompt (e.g., checkboxes, a text box, select-from list). 

This organizes the parameters for your PowerShell scripts into an accessible GUI executed as a job. And if you have Comment-based Help in your scripts, Otter will auto-generate these for your script. Check out this documentation page for more on the types of specific variable prompts Otter can create.

Step 5: Choose Your Server Targeting

Otter doesn’t just let your non-expert PowerShell users run scripts; it also allows those in charge to sleep more soundly at night by targeting only specific servers for a particular job or job template. Otter offers three types of server targeting:

TypeDescription
DirectBest used for set-ups with just one or two servers, “Direct” specifies servers by name, and the script is then run against each server. This method can use variable names.
IndirectAlthough it requires some planning ahead, “Indirect” specifies a combination of roles and/or environments that will be used to specify the servers the script is run against. This method can use variable names.
CustomThis method is the most flexible but also the most complex. “Custom” lets you perform complex orchestration that can run different commands or scripts on different servers. These servers can be targeted sequentially, in parallel, and with branching and iterating (looping) logic.

Step 6: Define Custom Server Targeting with Variables

To make sure scripts only ever run on the right servers, you’ll want to define your targeting to meet your specific requirements. To do this:

  1. Click “edit” on your job template.
  2. Choose “add” under “template variables (prompts).”
  3. Create your variable using the parameters you desire.
  4. Confirm that “Custom server targeting” is listed next to “server targeting”
  5. Commit changes.

Then, of course, test. If you’ve done everything right, when you (or anyone with access) go to create a job from that template, the targeting menu should look as you defined it. For example, I configured “TargetServer” to be a list-type variable with list values of testsv1, testsv2, and testsv3. I then tested the template and saw I did everything right:

You can find detailed instructions for this step here.

Choose to Use the Right Tool for the Job

Otter is designed to help you run scripts because it automatically generates a GUI around your PowerShell. Otter helps un-bottleneck your team and safeguard your systems without extra costs.

Running PowerShell scripts is just one way to enhance your PowerShell Usage. For many more ways to give your PowerShell scripts and modules a boost, take a look at our free eBook, “Ultimate Powershell Levelup Guide”. Sign up for your copy today!

Crista Perlton

Crista Perlton

Navigation