# Parameters

## Parameters

Jobs support automatically generating forms with parameters based on your script's `param` block. The type of control will change based on the type you define in the block. Parameters that are mandatory will also be required by the UI.

### Basic Parameters

Parameters can be simply defined without any type of parameter attribute and they will show up as text boxes in the UI.

```powershell
param($Test)

$Test
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MB4BLKFWBIF_Nf_DQDG%2F-MB4DnzruHtWQR7pMEZo%2Fimage.png?alt=media\&token=bd19051c-626d-47ac-ad1c-9aaa93bb84f7)

### Type Parameters

UA supports various types of parameters. You can use String, String\[], Int, DateTime, Boolean, Switch and Enum types.

#### String

You can define string parameters by specifying the `[String]` type of by not specifying a type at all. Strings will generate a textbox.

```powershell
param(
    [String]$Textbox,
    $Textbox2
)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY4BOoHNn9m2IvJYu0%2F-MMY57K6W1Wgq-QP9Efn%2Fimage.png?alt=media\&token=de2af9ed-7b5c-4955-a7da-03b917cff263)

#### String Arrays

You can specify string arrays by using the `[String[]]` type specifier. String arrays will generate a multi-tag select box.

```powershell
param([String[]]$Array)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY4BOoHNn9m2IvJYu0%2F-MMY5SjN481NALNb2asK%2Fimage.png?alt=media\&token=18b825c8-ab58-4a40-9f30-34284b5263ca)

#### Date and Time

You can use the `[DateTime]` type specifier to create a date and time selector.

```powershell
param([DateTime]$DateTime)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY4BOoHNn9m2IvJYu0%2F-MMY5eVdKyXqt40NXEVW%2Fimage.png?alt=media\&token=38072450-d7a2-43df-9c2f-59c6ac98a551)

#### Boolean

You can use a `[Bool]` type selector to create a switch.

```powershell
param([Bool]$Switch)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY4BOoHNn9m2IvJYu0%2F-MMY5tuZIQ2V_Va_YTJa%2Fimage.png?alt=media\&token=caef32af-a556-452a-abba-f4e3d2ec68bc)

#### Integer

You can define a number selector by using the `[Int]` type specifier.

```powershell
param([Int]$Number)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY79pnpSdI1ElpmwtB%2F-MMY7rhDbg3RqJGZZvWF%2Fimage.png?alt=media\&token=e3b8df18-5449-41ee-b7c5-d8a164ad6ec4)

#### Switch Parameter

You can define a switch parameter using the `[Switch]` type specifier to create a switch.

```powershell
param([Switch]$Switch)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY4BOoHNn9m2IvJYu0%2F-MMY67wc08eQuJt-h-iL%2Fimage.png?alt=media\&token=c33717ca-1be8-41de-ad98-7b30233557bc)

#### Enumerations

You can use System.Enum values to create select boxes. For example, you could use the `System.DayOrWeek` to create a day of the week selection box.

```powershell
param([System.DayOfWeek]$DayOfWeek)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY4BOoHNn9m2IvJYu0%2F-MMY6LxdVRIJkC7d4yPW%2Fimage.png?alt=media\&token=01303d10-ed18-4444-a121-4d109cc70a0e)

#### PSCredential

When you specify a `PSCredential` , the user will be presented with a drop down of credentials available as [variables](https://docs.powershelluniversal.com/master-1/platform/variables#creating-a-secret-variable).&#x20;

```powershell
param(
    [PSCredential]$Credential
)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2Fmr280xzGWHr5yP5ckPxI%2Fimage.png?alt=media\&token=a91cbfe7-7b3f-4362-96b7-3a341f98a1bc)

### Display Name

You can use the `DisplayNameAtrribute` to set a display name for the script parameter.&#x20;

```powershell
param(
    [ComponentModel.DisplayName("My Script")]
    $MyScript
)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2Fz6F9ETzR095u8Q0SlJrY%2Fimage.png?alt=media\&token=aba83605-a455-4911-8f74-119f10687f25)

### Help Messages

You can define help messages for your parameters by using the `HelpMessage` property of the `Parameter` attribute.

```powershell
param(
    [Parameter(HelpMessage = "Class you want to enroll in")]
    [string]$Class
)
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MMY4BOoHNn9m2IvJYu0%2F-MMY76SHgqRfPK0RCdlQ%2Fimage.png?alt=media\&token=00420db7-d5a1-4093-bd3d-a2558df0d188)

### Required Parameters

You can use the Parameter attribute to define required parameters.

```powershell
param(
    [Parameter(Mandatory)]
    $RequiredParameter
)

$RequiredParameter
```

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MB4BLKFWBIF_Nf_DQDG%2F-MB4E28hil_DldKDhYy-%2Fimage.png?alt=media\&token=024dd528-39e6-46f9-869d-2fa423df2be3)

## Passing Parameters from PowerShell

You can pass parameters from PowerShell using the `Invoke-UAJob` cmdlet. This cmdlet supports dynamic parameters. If you have a `param` block on your script, these parameters will automatically be added to `Invoke-UAJob`.

For example, I had a script named Script1.ps1 and the contents were are follows.

```powershell
param($MyParameter)

$MyParameter
```

I could then invoke that script using this syntax.

```powershell
Invoke-PSUScript -Name 'Script.ps1' -MyParameter "Hello"
```

The result would be that Hello was output in the job log and pipeline.

## Parameter Sets

{% hint style="info" %}
Available in PowerShell Universal 2.8 or later.
{% endhint %}

PowerShell Universal supports parameter sets. When a parameter set is defined, a drop down is provided that allows for switching between the sets.&#x20;

```powershell
param(
    [Parameter(ParameterSetName = 'Set1')]
    $Parameter1,
    [Parameter(ParameterSetName = 'Set2')]
    $Parameter2
)
```

![Parameter Sets](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2FYSOTjoM49c1hHQby4LbC%2Fimage.png?alt=media\&token=b36d655b-3653-4b52-b7ba-dbbd5a49bb14)
