Disable and Enable triggers in Azure Data Factory using PowerShell

Companies depend on efficient data processing and management systems to make informed decisions in the fast-moving business world. Azure Data Factory (ADF) is a highly effective cloud-based data integration service that allows organizations to orchestrate and automate data workflows easily. One of the critical features of ADF is the ability to activate and deactivate triggers, which are essential for controlling the execution of data pipelines and factory maintenance. This article will provide step-by-step instructions to enable and disable triggers in Azure Data Factory.

Pre-requisites:
1. Access to Data Factory resources in the Azure portal.
2. Az PowerShell module installed on the local machine.

Understanding Azure Data Factory Triggers

Azure Data Factory utilizes triggers to initiate data pipeline executions based on specific conditions automatically. These conditions can be set on a schedule, event, or through manual intervention. Triggers play a crucial role in ensuring that data pipelines run at the correct time, keeping data processing up-to-date and accurate. Turning triggers on-demand on and off gives data engineers the flexibility to control the data flow efficiently.

Script to disable and enable triggers in Azure Data Factory

Use the below PowerShell script to disable all the triggers in Azure Data Factory.

$adf_name = 'adfname'
$resourcegroup_name = 'resourcegroupname'

$triggersADF = Get-AzDataFactoryV2Trigger -DataFactoryName $adf_name -ResourceGroupName $resourcegroup_name; 
$triggersADF | ForEach-Object { Stop-AzDataFactoryV2Trigger -ResourceGroupName $resourcegroup_name -DataFactoryName $adf_name -Name $_.name -Force }

Use the below PowerShell script to enable all the triggers in Azure Data Factory.

$adf_name = 'adfname'
$resourcegroup_name = 'resourcegroupname'

$triggersADF = Get-AzDataFactoryV2Trigger -DataFactoryName $adf_name -ResourceGroupName $resourcegroup_name; 
$triggersADF | ForEach-Object { Start-AzDataFactoryV2Trigger -ResourceGroupName $resourcegroup_name -DataFactoryName $adf_name -Name $_.name -Force }

Manage ADF triggers in YAML based Azure DevOps pipeline

Use the script below to enable and disable triggers in adf using a YAML-based]deployment pipeline in Azure DevOps.

          deploy:  #Configure steps under deploy hook.
            steps:
              #task to disable triggers in Azure Data Factory.
              - task: AzurePowerShell@5     
                displayName: Stop Triggers
                inputs:
                  azureSubscription: 'subscriptionname'
                  ScriptType: 'InlineScript'
                  Inline: |
                    $triggersADF = Get-AzDataFactoryV2Trigger -DataFactoryName "$(dataFactoryName)" -ResourceGroupName "$(resourceGroup)"; 
                    $triggersADF | ForEach-Object { Stop-AzDataFactoryV2Trigger -ResourceGroupName "$(resourceGroup)" -DataFactoryName "$(dataFactoryName)" -Name $_.name -Force }
                  azurePowerShellVersion: 'LatestVersion'             
             
              #task to enable triggers in Azure Data Factory.
              - task: AzurePowerShell@5    
                displayName: Start Triggers
                inputs:
                  azureSubscription: 'subscriptionname'
                  ScriptType: 'InlineScript'
                  Inline: |
                    $triggersADF = Get-AzDataFactoryV2Trigger -DataFactoryName "$(dataFactoryName)" -ResourceGroupName "$(resourceGroup)";
                    $triggersADF | ForEach-Object { Start-AzDataFactoryV2Trigger -ResourceGroupName "$(resourceGroup)" -DataFactoryName "$(dataFactoryName)" -Name $_.name -Force }
                  azurePowerShellVersion: 'LatestVersion'

Pro tips:
1. It is important to disable triggers before deploying data factory code using Azure DevOps pipelines. Refer to this article if you want to automate Azure data factory deployments using the DevOps pipeline.

See more

Kunal Rathi

With over 13 years of experience in data engineering and analytics, I've assisted countless clients in gaining valuable insights from their data. As a dedicated supporter of Data, Cloud and DevOps, I'm excited to connect with individuals who share my passion for this field. If my work resonates with you, we can talk and collaborate.

Shopping Cart
Scroll to Top