PowerShell查询Azure Data Factory脚本报错,请求排查问题原因
Azure Data Factory PowerShell脚本报错排查
我拥有大量Azure Data Factory(ADF)实例,希望查看其详细信息,为此编写了如下PowerShell脚本:
# Connect to Azure account Connect-AzAccount # Header for displaying pipeline information $header = "ADF Location" + "`t" + "ResourceGroupName" + "`t" + "AdfName" + "`t" + "Pipeline Name" # List of Resource Groups to be searched for Azure Data Factory (ADF) Pipelines $RGs = "RG1", "RG2" # Iterate through each Resource Group to Get ADFs and Then Iterate through each ADF to get Pipelines List foreach ($ResourceGroupName in $RGs) { # Get list ADFs associated with the resource group $ADFs = Get-AzDataFactory -ResourceGroupName $ResourceGroupName # Iterate through each ADF to get list of Pipelines associated with the ADF foreach ($ADF in $ADFs) { # Get list of Pipelines for the ADF $Pipelines = Get-AzDataFactoryPipeline -ResourceGroupName $ResourceGroupName -DataFactoryName $ADF.DataFactoryName # Iterate through each pipeline to get detailed information foreach ($Pipeline in $Pipelines) { # Get Detailed information about the pipeline #$P = Get-AzDataFactoryPipeline -ResourceGroupName $ResourceGroupName -name $Pipeline.name -DataFactoryName $ADF.DataFactoryName # Print the Pipeline Name along with Location, Resource Group & ADF name Write-Output ($ADF.Location + "`t" + $ResourceGroupName + "`t" + $ADF.DataFactoryName + "`t" + $Pipeline.name) } # End of Pipelines loop } # End of ADFs loop } # End of Resource Groups Loop
执行脚本时出现如下错误:
HTTP Status Code: NotFound Error Code: InvalidResourceType Error Message: The resource type could not be found in the namespace 'Microsoft.DataFactory' for api version '2015-10-01'. Request Id: cc590f66-c00f-4a63-ae46-800f38436949 Timestamp (Utc):02/28/2024 15:20:24
问题原因
你使用的Get-AzDataFactory和Get-AzDataFactoryPipeline是针对ADF V1的旧版Cmdlet,当前主流的ADF实例都是ADF V2(正式名称为Azure Data Factory),旧版Cmdlet调用的API版本2015-10-01不支持V2资源类型,因此触发报错。
解决方法
替换为ADF V2对应的Cmdlet即可解决:
- 用
Get-AzDataFactoryV2替代Get-AzDataFactory - 用
Get-AzDataFactoryV2Pipeline替代Get-AzDataFactoryPipeline
修改后的完整脚本:
# Connect to Azure account Connect-AzAccount # Header for displaying pipeline information $header = "ADF Location" + "`t" + "ResourceGroupName" + "`t" + "AdfName" + "`t" + "Pipeline Name" # Print header Write-Output $header # List of Resource Groups to be searched for Azure Data Factory (ADF) Pipelines $RGs = "RG1", "RG2" # Iterate through each Resource Group to Get ADFs and Then Iterate through each ADF to get Pipelines List foreach ($ResourceGroupName in $RGs) { # Get list ADFs associated with the resource group (V2 cmdlet) $ADFs = Get-AzDataFactoryV2 -ResourceGroupName $ResourceGroupName # Iterate through each ADF to get list of Pipelines associated with the ADF foreach ($ADF in $ADFs) { # Get list of Pipelines for the ADF (V2 cmdlet) $Pipelines = Get-AzDataFactoryV2Pipeline -ResourceGroupName $ResourceGroupName -DataFactoryName $ADF.DataFactoryName # Iterate through each pipeline to get detailed information foreach ($Pipeline in $Pipelines) { # Print the Pipeline Name along with Location, Resource Group & ADF name Write-Output ($ADF.Location + "`t" + $ResourceGroupName + "`t" + $ADF.DataFactoryName + "`t" + $Pipeline.name) } # End of Pipelines loop } # End of ADFs loop } # End of Resource Groups Loop
内容的提问来源于stack exchange,提问作者Francesco Mantovani
相关产品推荐
相关产品推荐

