How to retrieve all Azure Data Factories through PowerShell script?

67 Views Asked by At

I have a vast park of Azure Data Factories and I would like to see it in details.

In order to do so I have this PowerShell script:

# 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

But once again gods are not on my side and they return me the error:

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

What am I doing wrong now?

ChatGPT replies like a broken toy... there is a long way before it takes over developers jobs...

2

There are 2 best solutions below

0
Francesco Mantovani On BEST ANSWER

The solution was that first of all you have to put yourself under that Subscription that is containing that Resource Group:

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

And then you can run:

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

Here the code:

# 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
        }
    }
}
2
Nandan On

The above powershell which you are using is for Azure data Factory V1 version which is no longer active.

Now we have Azure Data Factory V2, so you need to use the below version of powershell :

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

i.e Get-AzDataFactoryV2 rather than Get-AzDataFactory