azure - 如何强制删除具有引用的 ADF Pipeline

标签 azure powershell pipeline azure-data-factory

我实际上是 ADF 的自动化人员。作为其中的一部分,我尝试删除所有 ADF V2 管道。问题是我的管道有许多不同管道本身的引用。

$ADFPipeline = Get-AzDataFactoryV2Pipeline -DataFactoryName $(datafactory-name) -ResourceGroupName $(rg)



$ADFPipeline | ForEach-Object { Remove-AzDataFactoryV2Pipeline -ResourceGroupName $(rg) -DataFactoryName $(datafactory-name) -Name  $_.name -Force }

大多数时候我都会遇到这样的错误

The document cannot be deleted since it is referenced by "blabla"

我理解错误,它说一些引用并且无法删除。但是,当我在 azure 门户中尝试相同的删除时,无论我可以删除什么引用。所以我想找到一种方法,是否可以告诉Powershell,即使它有一个引用,也可以强制删除它

非常感谢任何其他输入!

最佳答案

我遇到了同样的问题,发现从管道的 Activity 属性构建整个依赖关系图相当复杂。

作为工作解决方案(powershell):

function Remove-Pipelines {
    param (
        [Parameter(Mandatory=$true)]
        [AllowEmptyCollection()]
        [AllowNull()]
        [System.Collections.ArrayList]$pipelines
    )
    if($pipelines.Count -gt 0) {
        [System.Collections.ArrayList]$plsToProcess = New-Object System.Collections.ArrayList($null)
        foreach ($pipeline in $pipelines) { 
            try {
                $removeAzDFCommand = "Remove-AzDataFactoryV2Pipeline -dataFactoryName '$DataFactoryName' -resourceGroupName '$ResourceGroupName' -Name '$($pipeline.Name)' -Force -ErrorAction Stop"
                Write-Host $removeAzDFCommand
                Invoke-Expression $removeAzDFCommand
            }
            catch {
                if ($_ -match '.*The document cannot be deleted since it is referenced by.*') {
                    Write-Host $_
                    $plsToProcess.Add($pipeline)
                } else {
                    throw $_
                }
            }
        }
        Remove-Pipelines $plsToProcess
    }
}

这是清除整个 DF 的完整解决方案:“trigger”、“pipeline”、“dataflow”、“dataset”、“linkedService”

Param(
  [Parameter(Mandatory=$true)][string] $ResourceGroupName,
  [Parameter(Mandatory=$true)][string] $DataFactoryName
)

$artfTypes = "trigger","pipeline","dataflow","dataset","linkedService"

function Remove-Artifacts {
    param (
        [Parameter(Mandatory=$true)][AllowEmptyCollection()][AllowNull()][System.Collections.ArrayList]$artifacts,
        [Parameter(Mandatory=$true)][string]$artfType
    )
    if($artifacts.Count -gt 0) {
        [System.Collections.ArrayList]$artToProcess = New-Object System.Collections.ArrayList($null)
        foreach ($artifact in $artifacts) { 
            try {
                $removeAzDFCommand = "Remove-AzDataFactoryV2$($artfType) -dataFactoryName '$DataFactoryName' -resourceGroupName '$ResourceGroupName' -Name '$($artifact.Name)' -Force -ErrorAction Stop"
                Write-Host $removeAzDFCommand
                Invoke-Expression $removeAzDFCommand
            }
            catch {
                if ($_ -match '.*The document cannot be deleted since it is referenced by.*') {
                    Write-Host $_
                    $artToProcess.Add($artifact)
                } else {
                    throw $_
                }
            }
        }
        Remove-Artifacts $artToProcess $artfType
    }
}

foreach ($artfType in $artfTypes) {
  $getAzDFCommand = "Get-AzDataFactoryV2$($artfType) -dataFactoryName '$DataFactoryName' -resourceGroupName '$ResourceGroupName'"
  Write-Output $getAzDFCommand

  $artifacts = Invoke-Expression $getAzDFCommand
  Write-Output $artifacts.Name

  Remove-Artifacts $artifacts $artfType
}

同样的方法也适用于“Set-AzDataFactoryV2Pipeline”命令。

值得一提的是,除了依赖项跟踪之外,删除/设置工件的顺序应该是正确的(因为跨工件的依赖项)。

对于集合 - “linkedService”、“数据集”、“数据流”、“管道”、“触发器”

对于删除 - “触发器”、“管道”、“数据流”、“数据集”、“linkedService”

关于azure - 如何强制删除具有引用的 ADF Pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58559980/

相关文章:

visual-studio - 如何使用 PowerShell 更改 VS 包管理器控制台的前景色?

azure - 如何提高azure搜索性能

amazon-web-services - cloudformation将参数传递给ssm文档

Azure Maps 路线方向 - 错误请求

powershell - 如何在powershell中返回具有相同扩展名但包含特定名称结尾的文件?

devops - 在 Gitlab-ci 中,有一种方法仅在规则匹配后才在脚本之前运行

c - 管道命令./a.out | cat, printf ("line\n") in a.out 未执行且无输出

f# - 管道中的 printfn

powershell - 如何使用 Powershell 递归通过目录树查找文件

azure - 如何在 Azure 的 ARM 模板中指定无服务器数据库?