> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/automation/scripts/parameters.md). Agents can also search and read this documentation through its [MCP server](https://docs.devolutions.net/~gitbook/mcp).

# Parameters

Generate PowerShell Universal job input forms automatically from script param blocks, supporting types like DateTime, PSCredential, File, and ValidateSet.

## 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
```

### Parameters Types

Universal supports various types of parameters. You can use String, String\[], Int, DateTime, Boolean, Switch and Enum types, as well as PSCredential, SecureString, File, DateOnly and TimeOnly.

The following table lists the control generated for each parameter type.

| Parameter type                                   | Control                             |
| ------------------------------------------------ | ----------------------------------- |
| `[String]` or no type                            | Text box                            |
| `[String[]]`                                     | Multi-tag select box                |
| `[Int]` (`System.Int32`)                         | Number input                        |
| `[DateTime]`                                     | Date and time picker                |
| `[DateOnly]`                                     | Date picker                         |
| `[TimeOnly]`                                     | Time picker                         |
| `[Bool]` or `[Switch]`                           | Checkbox                            |
| Enumeration, or any parameter with `ValidateSet` | Select box                          |
| `[PSCredential]`                                 | Drop down of PSCredential variables |
| `[SecureString]`                                 | Password box                        |
| `[File]` or `[PowerShellUniversal.PSUFile]`      | File upload                         |
| Any other type                                   | Text box                            |

Other numeric types, such as `[long]` or `[double]`, are displayed as text boxes. A `ValidateSet` on a `[String[]]` parameter keeps the multi-tag select box and offers the listed values in its drop down.

#### 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
)
```

#### 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)
```

#### Date and Time

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

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

#### Boolean

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

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

#### Integer

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

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

#### Switch Parameter

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

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

#### Enumerations

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

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

#### PSCredential

When you specify a `PSCredential` , the user will be presented with a drop down of credentials available as [variables](https://docs.devolutions.net/powershell-universal/platform/variables.md#creating-a-secret-variable).

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

#### File

You can allow users to upload files by using the `[File]` type.

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

When a user picks a file for this parameter in the admin console, the console uploads it and shows "File uploaded successfully.", or "File upload failed." when the upload does not return a file.

Files will be available as a `PSUFile` object in your scripts. This object has a `byte[]` array that you can use to process the file. The `FileName` property contains the name of the uploaded file and the `Content` property contains its bytes.

For example, you can get the string content for the file by converting it using the Encoding classes.

```powershell
[Text.Encoding]::UTF8.GetString($File.Content)
```

### Display Name

You can use the `DisplayNameAttribute` to set a display name for the script parameter. Without it, the parameter name is split on capital letters, so `$ComputerName` is displayed as `Computer Name`.

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

### 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
)
```

### Required Parameters

You can use the Parameter attribute to define required parameters.

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

$RequiredParameter
```

A parameter with the `[ValidateNotNull()]` attribute is also required in the UI.

### Default Value

You can use both static and default values for parameters. The default value is calculated when the job is about to be run.

```powershell
param(
    $Parameter = "Hello, World",
    [DateTime]$ExecutionTime = Get-Date
)

$Parameter
$ExecutionTime
```

## ValidateSet

The `ValidateSet` attribute is used to enforce which values can be passed to a parameter. Learn about [ValidateSet here.](https://duckduckgo.com/?q=validateset\&ia=web) PowerShell Universal will automatically create a drop-down menu with the values provided to the `ValidateSet` attribute for parameters.

For example, a script could define a param block as follows.

```powershell
param(
    [ValidateSet("Steve", "Mary")]
    [string]$Name
)
```

## Passing Parameters from PowerShell

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

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

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

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

Parameters that belong to all parameter sets are shown in a set named `Default`. When the script has more than one parameter set and `CmdletBinding` does not define a `DefaultParameterSetName`, the first set is selected when the run dialog opens.

## Hidden Parameters

Parameters marked with `[Parameter(DontShow)]` are not displayed in the run dialog.

```powershell
param(
    [Parameter(DontShow)]
    $InternalValue = 'Default'
)
```

PowerShell common parameters, such as `Verbose`, `Debug`, `ErrorAction`, `WarningAction`, `InformationAction`, `ErrorVariable`, `WarningVariable`, `InformationVariable`, `OutVariable`, `OutBuffer`, `PipelineVariable`, `WhatIf`, `Confirm`, and `ProgressAction`, are never displayed as script parameters.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/powershell-universal/automation/scripts/parameters.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
