如何通过PowerShell脚本检索所有Azure数据工厂?

问题描述 投票:0回答:2

我有一个巨大的 Azure 数据工厂园区,我想详细了解它。

为此,我有这个 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

我现在做错了什么?

ChatGPT 的回复就像一个坏掉的玩具……距离它接管开发人员的工作还有很长的路要走……

powershell scripting azure-data-factory azure-powershell azure-cli
2个回答
0
投票

您使用的上述 powershell 适用于 Azure data Factory V1 版本,该版本不再有效。

现在我们有Azure Data Factory V2,因此您需要使用以下版本的powershell:

https://learn.microsoft.com/en-us/powershell/module/az.datafactory/get-azdatafactoryv2?view=azps-11.3.0

即 Get-AzDataFactoryV2 而不是 Get-AzDataFactory


0
投票

解决方案是,首先您必须将自己置于包含该资源组的订阅下:

Connect-AzAccount -Subscription aa48e218-****-****-****-1adcc957ef94 -TenantId 363c9387-****-****-****-93d71a8c1e9b

然后你可以运行:

Get-AzDataFactoryV2 -ResourceGroupName my-eus-rg-name-rg

这里是代码:

# Step 1: Login into Azure
Connect-AzAccount

# Step 2: Iterate through each subscription
$subList = Get-AzSubscription

foreach ($subscription in $subList) {
    Select-AzSubscription -SubscriptionId $subscription.Id

    # Print subscription name in green
    Write-Host "Subscription: $($subscription.Name)" -ForegroundColor Green

    # Step 3: Iterate on each Resource Group
    $resourceGroups = Get-AzResourceGroup

    foreach ($resourceGroup in $resourceGroups) {
        # Step 4: List the Azure Data Factories in each Resource Group
        $dataFactories = Get-AzDataFactoryV2 -ResourceGroupName $resourceGroup.ResourceGroupName -ErrorAction SilentlyContinue

        if ($dataFactories) {
            $output = "Resource Group: $($resourceGroup.ResourceGroupName), Azure Data Factories: "
            $output += ($dataFactories | ForEach-Object { $_.DataFactoryName }) -join ', '
            Write-Output $output
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.