Add-QlikTrigger.ps1

function Add-QlikTrigger {
    <#
    .SYNOPSIS
    This function ...
 
    .DESCRIPTION
    A bit more description
 
    .PARAMETER FromPipeline
    Shows how to process input from the pipeline, remaining parameters or by named parameter.
 
    .EXAMPLE
    Add-QlikTrigger 'abc'
 
    Description of the example.
 
    #>


    <# Enable -Confirm and -WhatIf. #>
    [CmdletBinding(SupportsShouldProcess = $true)]
    param (
    [parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True,Position=0)]
    [alias("id")]
    [string]$taskId,
    [string[]]$OnSuccess,
    [string]$date
  )

    begin {
    }

    process  {
    If( $tags ) {
      $tagArray = @(
        $tags | foreach {
          $p = Get-QlikTag -filter "name eq '$_'"
          @{
            id = $p.id
          }
        }
      )
    } else {
      $tagArray = @();
    }

    $task = Get-QlikReloadTask -id $taskId -raw

    If($date) {
      $date = Get-Date -Format yyyy-MM-ddTHH:mm:ss.000Z $date
      $update = @{
        schemaEvents = @(@{
          name = "Daily";
          enabled = $true;
          eventType = 0;
          startDate = "$date";
          expirationDate = "9999-12-30T23:59:59.999Z";
          schemaFilterDescription = @("* * - * * * * *");
          incrementDescription = "0 0 1 0";
          incrementOption = "2";
          reloadTask = @{
            id = $task.id
          }
        })
      }
    } else {
      $update = @{
        compositeEvents = @(
          @{
            name="TRANSFORM OnSuccess";
            enabled=$true;
            eventType=1;
            reloadTask = @{
              id = $task.id
            }
            timeConstraint=@{
                    seconds = 0;
                    minutes = 360;
                    hours = 0;
                    days = 0;
            };
            compositeRules=@($OnSuccess | foreach {
              @{
                ruleState=1;

                reloadTask=@{
                  id=$_
                }
              }
            });
            privileges=@("read","update","create","delete")
          }
        )
      }
    }

    $json = $update | ConvertTo-Json -Compress -Depth 10

    return Invoke-QlikPost "/qrs/reloadtask/update" $json
  }

    end {
    }
}

if ($loadingModule) {
    Export-ModuleMember -Function 'Add-QlikTrigger'
}