0
votes

I want to retrieve the list of subscriptions having Azure Data Factory resource in it. I want to use PowerShell and get the subscription list and ADF list.

I have tried Get-AzSubscription, but it does not contain filter for resource type i.e. Microsoft.DataFactory/factories. This filter can be added to only Get-AzResource.

  1. Get-AzSubscription Module
  2. Get-AzResource Module
1
Hello! Do you already have something to start with? Anything that you already tried, that someone can help add on to?Ked Mardemootoo
@Ked - updated the Question details section.Yogesh Kulkarni

1 Answers

0
votes

Ok here you are:

$resType     = "Microsoft.DataFactory/factories"
$resTypeName = "DataFactory"
Get-AzSubscription | ForEach-Object {
    $subscriptionName = $_.Name
    $tenantId = $_.TenantId
    Set-AzContext -SubscriptionId $_.SubscriptionId -TenantId $_.TenantId
    (Get-AzResource -ResourceType $ResType) | ForEach-Object {     
        [PSCustomObject] @{
            true_sub = $subscriptionName
        } 
    } | get-unique 
} | Select-String 'true_sub' | ForEach-Object{ "Found_" + "$resTypeName" + "_In_Subscription= $($subscriptionName)"}

EDIT: Added variables to make it easily reusable for any resource type.

I used the code available here and here to create a custom one based on the requirements. Tested in my environment - it seems to work as expected.

I should disclose that I'm not an advanced PowerShell user, so the code I'm providing could really be sub-optimal.