Triggers
Trigger scripts when events happen with PowerShell Universal.
Last updated
Trigger scripts when events happen with PowerShell Universal.
Last updated
Copyright 2024 Ironman Software
Triggers require a license.
Triggers allow for automation jobs to be started when certain events happen within PowerShell Universal. For example, this allows you to take action when jobs complete, the server starts or dashboards stop. Triggers are useful for assigning global error handling or sending notifications when certain things happen.
Triggered jobs will not cause additional triggers to start. Triggers are stored in the triggers.ps1
.
The following types of events can be assigned a trigger.
Job Started
Job Completed
Job Requesting Feedback
Job Failed
Dashboard Started
Dashboard Stopped
Server Started
Server Stopping
User Login
Use of a Revoked App Token
PowerShell Protect Event
API Authentication Failed
API Error
New User Login
Git Sync
License Expired
License Expiring
The user login event takes place when a user accesses PowerShell Universal. The script will receive a $User
parameter with user information.
The user login event takes place when a user accesses PowerShell Universal. The script will receive a $data
parameter with user information. The data structure is shown below.
The app token event takes place when a revoked app token is used. The script will receive a $data
parameter that contains the contents of the app token as a string.
This trigger occurs when a git sync is run. This trigger will fire for both successful and unsuccessful git syncs.
You will receive the following object in the $data
parameter.
Global triggers will start the assigned script whenever the event type is invoked.
For example, the Script.ps1
will be run whenever any job is run.
Resource triggers will start the assigned script when the event takes place on the selected resource.
For example, the Script.ps1
will be run whenever the Dashboard
is stopped.
Whenever a job is started from a trigger, it will be provided with metadata about object that caused the event to trigger.
Triggers related to jobs will be provided a $Job
parameter.
Triggers related to dashboards will be provided a $Dashboard
parameter.
Triggers related to the server status will not receive a parameter.
Using the -Condition
parameter of New-PSUTrigger
, you can determine whether or not a trigger should be run based on local conditions on the server. Return $true
or $false
from the condition.
For example, you can disable a trigger if the Environment
environment variable is not set to production
.