Use named parameters in scripts

If your script supports named parameters, you can reference parameters by name in your script. The key-value pairs that you specify are passed to the script at runtime. 

Note: Named parameters are supported only in PowerShell scripts.

This walkthrough demonstrates how to use named parameters within a simple PowerShell (ps1) script. 

Step 1: Create a script

  1.  From the menu bar, click Smart Build.
  2. Click New Script.
  3. Enter the name of the script as Named Parameters.
  4. Enter Type (File Ext) as ps1 and click Next.
  5. Enter the following PowerShell code in the script source editor and click Next:
    param 
    (
    $Computer,
    $Filepath
    )
    $Computer
    $Filepath
  6. Under Script Parameters, select Use named parameters.
  7. Enter the following parameters:
    Type Key Value
    String Computer FL-Sally.acme.net
    String Filepath C:\Users\acme\weekly-status 

    The image below shows these entries as they would appear in the script editor:

    named-parameters.png
  8. Click Next and click Finish.

Step 2: Run the script on a machine

  1. From the menu bar, click Smart Build.
  2. Move the pointer over the script and select Actions > Deploy.
  3. Provide a job name, select a machine, and click Next.
  4. Select Run Now and click Next.
  5. Review the parameters and click Next.
  6. Click Finish. The script job runs and a status notification is sent to your registered email address.

Step 3: View job details

  1. From the menu bar, click Smart Build.
  2. Move the pointer over the script and select Actions > View.
  3. Click View Jobs.
  4. Under Instances, click the job name.
  5. Under Runs, click the run instance.
    Step details appear.
  6. Click the Step Output tab. Step results appear.

A workflow summary including the key-value pairs, and the script output is illustrated in the following image: 

workflow-summary.png

0 Comments