Adding a second trigger in task schedule
<p>Have a powershell script that will create a scheduled task, for deployment, by way of Octopus, to a Windows 2012 server.</p>

<pre><code>Function Create-ScheduledTask($TaskName,$RunAsUser,$TaskRun,$Schedule,$StartTime,$StartDate,$Arguments,$RunWithElevatedPermissions,$Days,$Password){
    # set up
    $Command = "schtasks.exe /create /ru `"$RunAsUser`" /tn `"$TaskName`" /tr `"'$($TaskRun)' $Arguments`" $cmdSchedule $cmdDays $cmdStartDate $cmdStartTime /F $cmdInterval $cmdDuration $cmdRunLevel $cmdPassword"

    echo $Command
    Invoke-Expression $Command            
 }
</code></pre>

<p>Attempting to add another trigger as part of the same taskname, on the command line, will not work with <code>schtasks.exe</code> which seemingly contradicts the GUI where it can be done.</p>

<p>This is the function that was used to create the event trigger, ideally, to attach that to the same scheduled task.</p>

<pre><code>Function Create-ScheduledTaskEvent($TaskName,$RunAsUser,$TaskRun,$Arguments,$RunWithElevatedPermissions,$Password, $xPath, $channelName){

    $cmdRunLevel = if(-Not $RunWithElevatedPermissions){""}else{"/rl HIGHEST"}
    $cmdPassword = if([string]::IsNullOrEmpty($Password)){""}else{"/rp `"$Password`""}
    $cmdXPath = if([string]::IsNullOrEmpty($xPath)){""}else{"/sc ONEVENT /MO `"$xPath`" "}
    $cmdRunLevel = if(-Not $RunWithElevatedPermissions){""}else{"/rl HIGHEST"}

    $Command = "schtasks.exe /create $cmdRunLevel /ru `"$RunAsUser`" $cmdXPath /tn `"$TaskName`" /tr `"'$($TaskRun)' $Arguments`" /ec `"$channelName`" "

    echo $Command          
    Invoke-Expression $Command            
 }
</code></pre>

<p>Issue is, replacing the switch <code>/create</code> with <code>/change</code> only ends up clobbering the previous scheduled task's trigger/action.</p>

<p>Any idea how can this be done by way of <code>schtasks.exe</code> on the command-line, to combine the triggers into one.</p>

<p>It could be done by creating a separate task schedule with different taskname, it is not ideal though, nor is exporting out task as xml and then importing back in. </p>