[SOLVED] Get all container registries under a subscription – .NET Azure sdk


Looking out for .NET SDK references to get a specified container registry or all the container registries in a resource group or the subscription.

Need references apart from the REST API available:

I have seen that the operation is available through Powershell and CLI cmdlet; Get-AzContainerRegistry and az acr list, but looking out for .NET SDK based library references (Azure.ResourceManager preferred) for the same.

I have gone through https://github.com/Azure/azure-sdk-for-net, but there’s no extension related to get a specific or list the container registries under a subscription.


Nuget packages:

// Change these as needed
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();

// You can also get the resource group first if you know it already
// subscription.GetResourceGroups().Get("myresourcegroup");
var registyResources = subscription.GetGenericResourcesAsync("resourceType eq 'Microsoft.ContainerRegistry/registries'").AsPages();

await foreach (var resource in registyResources)
    var id = resource.Values.First().Id;
    Console.WriteLine($"Id: {id}");
    Console.WriteLine($"Resource Group: {id.ResourceGroupName}");
    Console.WriteLine($"Container registry name: {id.Name}");

You can also explore the returned resource if you need any other information. You can then continue with the specialized SDK for the specific Container Registry.

Answered By – Alex AIT

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *