Ironman Software Forums
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
PowerShell Universal is a platform for building web-based tools with PowerShell. One of the main features of PowerShell Universal is the ability to run PowerShell scripts on a schedule. In this post, we’ll look at the various ways to configure PSU schedules.
To create a basic schedule, you first need a script to schedule. Create a script by clicking Automation \ Scripts and then Create New Script.
Once the script has been created, you can click Automation \ Schedules and click Create new Schedule.
To create a simple schedule, select the script you wish to schedule and select the time you would like to schedule. Some basic options include Every Minute, Every Hour and Every Day at Midnight.
Once scheduled, you will be able to see the next execution time of the schedule.
A continuous schedule run over and over again with a delay in between each execution. This is useful for scripts you wish to run as soon as possible but may take a variable amount of time between each execution.
To create a continuous schedule, click Create New Schedule and then go to the Continuous tab. Input the number of seconds to delay in between each execution.
Once scheduled, the execution time will be listed as soon as possible.
CRON expressions are helpful for defining custom, complex scheduling.
To create a CRON schedule, click Create new Schedule and then go to the CRON tab. Enter the CRON expression. Once created, the next execution time will be listed in the schedule table.
A one-time schedule will run once in the future. To create a one-time schedule, click Create New Schedule and click the One-Time tab. Select the time in the future you would like it to run.
Scripts that define a param
block can accept parameters based on the schedule. To accept parameters in your script, adjust the contents to include a param
block.
param($MyParameter)
$MyParameter
Now when you schedule a script, you will have the option to define parameters for the script.
Environments define which version or configuration of PowerShell to execute the scheduled script in. By default, PowerShell Universal runs scripts in the Integrated environment. The integrated Environment runs within the PowerShell Universal server. If you wish to run in an alternate version of PowerShell, select the environment when defining your schedule.
To run a schedule as another user, you first need to define the user’s credentials. You can do so by creating a secret variable. Click Platform \ Variables. Then click Create New Variable and select the Secret tab.
Once you have a credential variable created, you can create a schedule and specify the account to run the schedule as.
You can use the schedules.ps1
file to configure schedules via PowerShell script. To edit or view the configuration file, navigate to Settings \ Configurations and click schedules.ps1.
A schedules that are defined in the UI will show within this file. You can also edit the file manually to add new schedules.
New-PSUSchedule -Cron "* * * * *" -Script "Script.ps1" -TimeZone "America/Denver" -Credential "MyUser"
New-PSUSchedule -Script "Script.ps1" -TimeZone "America/Denver" -Continuous -Delay ([System.TimeSpan]::FromSeconds(10)) -Credential "Default"
New-PSUSchedule -Cron "0 */8 * * *" -Script "Script.ps1" -TimeZone "America/Denver" -Credential "Default"
You can view the resulting jobs based on your schedules by navigating to Automation \ Jobs. Each scheduled run will be listed within the jobs page.
Find this useful? Please consider sharing this article. Have a question about PowerShell? Contact us and we'll write a post about it.
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
Receive once-a-month updates about Ironman Software. You'll learn about our product updates and blogs related to PowerShell.