如何获取Azure Data Factory(ADF)管道中的活动数量?批量场景下的非手动方案咨询
You definitely don’t have to rely on manual counting—there are several automated approaches to get the activity count for all your ADF pipelines across instances. Here are the most practical methods tailored to your scale:
1. PowerShell Script (Recommended for simplicity)
You can use the Azure PowerShell module to fetch pipeline details and count activities programmatically. The Get-AzDataFactoryV2Pipeline cmdlet returns the full pipeline definition, which includes an Activities array—we just need to count the length of that array for each pipeline.
Here’s a ready-to-use script that loops through all your ADF instances and outputs activity counts:
# Connect to your Azure account Connect-AzAccount # Optional: Set target subscription if you have multiple # Set-AzContext -SubscriptionId "your-subscription-id" # Initialize array to store results $results = @() # Get all ADF instances in your subscription $adfInstances = Get-AzDataFactoryV2 foreach ($adf in $adfInstances) { Write-Host "Processing ADF: $($adf.DataFactoryName) (Resource Group: $($adf.ResourceGroupName))" # Fetch all pipelines in the current ADF $pipelines = Get-AzDataFactoryV2Pipeline -ResourceGroupName $adf.ResourceGroupName -DataFactoryName $adf.DataFactoryName foreach ($pipeline in $pipelines) { # Count activities in the pipeline $activityCount = $pipeline.Activities.Count # Add to results set $results += [PSCustomObject]@{ DataFactoryName = $adf.DataFactoryName ResourceGroupName = $adf.ResourceGroupName PipelineName = $pipeline.Name ActivityCount = $activityCount } } } # Display results in a readable table $results | Format-Table -AutoSize # Optional: Export to CSV for analysis $results | Export-Csv -Path "ADFPipelineActivityCounts.csv" -NoTypeInformation
2. Azure Resource Graph Query
For a no-script, query-based approach, use Azure Resource Graph to get counts directly. This works great for quick ad-hoc checks or integrating into dashboards.
Run this Kusto query in the Azure Portal’s Resource Graph Explorer:
resources | where type == "Microsoft.DataFactory/factories/pipelines" | extend activityCount = array_length(properties.activities) | project DataFactoryName = split(id, '/')[8], ResourceGroupName = resourceGroup, PipelineName = name, ActivityCount = activityCount | order by DataFactoryName, PipelineName
You can export the results to CSV or Excel directly from the portal.
3. ADF REST API (For custom solutions)
If you want to build a custom tool, use the ADF REST API’s Pipeline_Get endpoint. For each pipeline, send a GET request to:https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}?api-version=2018-06-01
The response includes an activities array—count its elements to get the activity number. Automate this with tools like Python, Postman, or any HTTP client.
All these methods eliminate manual work, which is critical given your scale of 20+ ADF instances and multiple pipelines each. Pick the one that aligns best with your workflow!
内容的提问来源于stack exchange,提问作者Priya Jha

