使用 powershell 从 azure 数据工厂中的管道中删除触发器引用

Remove trigger reference from pipeline in azure data factory using powershell

我有一个管道,它在 Azure 数据工厂中关联了触发器。我正在尝试使用 powershell 命令自动执行 azure 数据工厂中的一些操作。在一个用例中,我被阻止了。

用例: 用户更改了与触发器关联的管道名称。 (这只是示例,实际上数据工厂中可能有许多 pipelines/triggers,用户可能会更改单个或多个管道)

触发器名称:TRG_Test1

管道名称:PL_Test1

所以 TRG_Test1 触发器附加到管道 PL_Test1。

要求: 用户将名称从 PL_Test1 更改为 PL_Test1_Updated ,关联的触发器应分离(删除)管道,然后删除管道并使用新名称创建新管道并附加(关联)相同的触发器。

注意:触发器细节没有变化,只有管道细节发生了变化。

通过使用 powershell 的变通方法,我能够使用 powershell 脚本确定哪个管道与哪个触发器相关联。 但是我无法在删除管道之前分离管道。

错误:

无法删除文档,因为它被

引用

Set-AzDataFactoryV2Trigger:当触发器与管道分离并更改以影响管道时,我正在使用此 powershell 命令。

是否有任何 powershell 命令仅删除管道引用? 任何替代/变通过程来删除管道的引用?

    ## Detach/Update the trigger
   Set-AzDataFactoryV2Trigger -ResourceGroupName $ADFDeployResourceGroupName -Name $triggerName -DataFactoryName $DataFactoryName -File /$triggerName.json" -Force
                                        
    ##Remove Pipeline
    #Remove-AzDataFactoryV2Pipeline -ResourceGroupName $ADFDeployResourceGroupName -Name $PipelineFileName -DataFactoryName $DataFactoryName -Force

如果要移除触发器中的管道引用,请参考以下代码

Connect-AzAccount


$sub=""
$groupName=""
$factoryName=""
$triggerName=""

Select-AzSubscription -Subscription $sub

$sw=Get-AzResource -ResourceId "/subscriptions/$sub/resourceGroups/$groupName/providers/Microsoft.DataFactory/factories/$factoryName/triggers/$triggerName“ -ExpandProperties


#remove the piplines reference
$pipName="Test" // the pipeline you want to remove
$sw.Properties.pipelines =($sw.Properties.pipelines -ne ($sw.Properties.pipelines|Where-Object{$_.pipelineReference.referenceName -eq $pipName}))

$s=Set-AzResource -ResourceId "/subscriptions/$sub/resourceGroups/$groupName/providers/Microsoft.DataFactory/factories/$factoryName/triggers/$triggerName“   -Properties $sw.Properties -Force