> 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/powershell-commands/new-psutrigger.md).

# New-PSUTrigger

## SYNOPSIS

Creates a new Automation trigger in PowerShell Universal.

## SYNTAX

```
New-PSUTrigger -Name <String> -EventType <EventType> -TriggerScript <Script> [-Script <Script>]
 [-Dashboard <Dashboard>] [-Environment <String>] [-Delay <Int32>] [-Computer <String>]
 [-Condition <ScriptBlock>] [-ComputerName <String>] [-AppToken <String>] [-Credential <PSCredential>]
 [-UseDefaultCredentials] [-Integrated] [-TrustCertificate] [-Cookies]
 [<CommonParameters>]
```

## DESCRIPTION

Creates a new Automation trigger in PowerShell Universal. Powershell Universal Automation triggers allow you to execute scripts based on events within PowerShell Universal. You can run scripts when other scripts fail, dashboards stop or when the server is starting up.

Triggers are stored within the ./universal/triggers.ps1 file.

You can also use this cmdlet to create triggers through the REST API.

## EXAMPLES

### Example 1

```powershell
New-PSUTrigger -Name 'Script Failed' -EventType JobFailed -TriggerScript 'ScriptFailed.ps1'
```

Creates a new trigger that calls the ScriptFailed.ps1 file when any job within PowerShell Universal fails.

### Example 2

```powershell
New-PSUTrigger -Name 'Dashboard Stopped' -Dashboard 'MyDashboard' -EventType DashboardStopped -TriggerScript 'DashboardStopped.ps1'
```

Creates a new trigger that calls the DashboardStopped.ps1 file when the dashboard MyDashboard stops.

### Example 3

```powershell
New-PSUTrigger -Name 'Server Started' -EventType ServerStarted -TriggerScript 'LogServerStart.ps1'
```

Creates a new trigger that calls the LogServerStart.ps1 file when the PowerShell Universal server is started.

## PARAMETERS

### -AppToken

The app token for accessing the PowerShell Universal Management API.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ComputerName

The computer name or URL of the Powershell Universal server.

```yaml
Type: String
Parameter Sets: (All)
Aliases: Uri

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Dashboard

Triggers for a specific dashboard.

```yaml
Type: Dashboard
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Environment

The environment to run the triggered script in.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -EventType

The event that causes this trigger.

```yaml
Type: EventType
Parameter Sets: (All)
Aliases:
Accepted values: JobCanceled, JobFailed, JobCompleted, JobStarted, JobFeedbackRequested, ServerStarted, ServerStopped, DashboardStarted, DashboardStopped

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Name

The name of this trigger. This needs to be unique.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Script

The script that causes this trigger.

```yaml
Type: Script
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TriggerScript

The script to trigger when this trigger is triggered.

```yaml
Type: Script
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -UseDefaultCredentials

Use default credentials when connecting to the management API

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Delay

Specifies the delay between executions.

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Integrated

Executes the command internally rather than using the Management API. Only works when running script from within PowerShell Universal.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Computer

The computer or queue to run this trigger on.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Condition

A condition script block to determine whether or not to run this trigger.

```yaml
Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Credential

Credentials to login to the PowerShell Universal Management API.

```yaml
Type: PSCredential
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TrustCertificate

Whether the cmdlet should ignore certificate issues.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Cookies

Reuses and persists authentication cookies for the current PowerShell session.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction. For more information, see [about\_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### System.Object

## NOTES

## RELATED LINKS

[New-PSUScript](/powershell-universal/powershell-commands/new-psuscript.md) [New-PSUDashboard](/powershell-universal/powershell-commands/new-psudashboard.md) [Get-PSUDashboard](/powershell-universal/powershell-commands/get-psudashboard.md) [Get-PSUScript](/powershell-universal/powershell-commands/get-psuscript.md)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/powershell-commands/new-psutrigger.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
