How to delete the ADFPipeline which is having the references Forcefully

浪子不回头ぞ 提交于 2020-01-25 07:54:05

问题


I'm actually some automation for my ADF. As a part of that, I'm trying to delete all the ADF V2 pipelines. The problem is my pipelines having many references with different pipelines itself.

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



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

And most of the time I get the error like

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

I understand the error that it saying some references and cannot be deleted. However, when I tried the same deletion in the azure portal, irrespective of the reference I can able to delete. So I want to find a way that whether it possible to tell that Powershell even though it's having a reference delete it forcefully

Any other inputs much appreciated!


回答1:


Hello and thank you for the question. According to the Remove-AzDataFactoryV2Pipeline doc, the -Force flag simply skips the confirmation prompt. It does not actually 'Force' the deletion in spite of errors.

Since you are already doing automation, might I suggest leveraging the error message to recursively attempt to delete the referencing pipeline. $error[0] gets the most recent error.

(Pseudocode)

try_recurse_delete( pipeline_name )
    do_delete(pipeline_name)
    if not $error[0].contains("referenced by " + pipeline_name)
        then return true
    else
        try_recurse_delete( get_refrencer_name($error[0]) )

Given that pipeline dependencies can be a many-to-many relationship, subsequent pipelines in your for-each loop might already be deleted by the recursion. You will have to adapt your code to react to 'pipeline not found' type errors.



来源:https://stackoverflow.com/questions/58559980/how-to-delete-the-adfpipeline-which-is-having-the-references-forcefully

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!