We help IT Professionals succeed at work.

Powershell - Register Scheduled Task - How to add a second trigger

String :-)
String :-) used Ask the Experts™
on
I use this script to register a scheduled Task

$Trigger= New-ScheduledTaskTrigger -At 7:01am -Daily
$User= "NT AUTHORITY\SYSTEM"
$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File D:\scripts\Get_Stuff_DO_Stuff.ps1"
Register-ScheduledTask -TaskName "TASKXYZ" -Trigger $Trigger -User $User -Action $Action -RunLevel Limited –Force

The business require a second trigger added at 7:01pm, therefore my question how to add a second trigger to this task. Many thanks String
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
The Trigger argument accepts an array, so you can just do something like this:
$Triggers = @()
$Triggers += New-ScheduledTaskTrigger -At 7:01am -Daily
$Triggers += New-ScheduledTaskTrigger -At 7:01pm -Daily
$User= "NT AUTHORITY\SYSTEM"
$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File D:\scripts\Get_Stuff_DO_Stuff.ps1"
Register-ScheduledTask -TaskName "TASKXYZ" -Trigger $Triggers -User $User -Action $Action -RunLevel Limited –Force

Open in new window

String :-)Windows Engineer

Author

Commented:
Bingo. Works a treat (and great learning exercise).
Thanks a bunch oBdA