Azure – Resource Providers with PowerShell and CLI

Hello Everybody,

Today we will continue with our last post Azure – Resource and Resource group and discuss about one more useful component of Microsoft Azure before proceed with Azure Resource Manager(ARM).

The resources in our resource groups are created and managed by Resource Providers. Each resource provider knows, how to manage and configure their resource.

Architecturally, this is a big change in Azure, because it means that new resource types can be developed, Deploy and exposed through a single management pane (ie: ARM) rather than having resource specific API’s which is the case for the old service management API’s.

There are different approaches available to deals with Azure Resource provider. Lets go through one by one. Today in this blog we will go with PowerShell and Azure CLI .In our next article, we will describe, how to work with Azure Resource Provider through Azure Portal.

  1. Power Shell:
    • View all resource providers in Azure :
      Using the following command we can get all resource providers in Azure for my subscription.

      Get-AzureRmResourceProvider -ListAvailable | Select-Object

      Get all information of Resource Providers
      Figure 1: Azure – Get all information of Resource Providers

      Using the following command we can get all resource providers in Azure with specific information for my subscription like registration status.

      Get-AzureRmResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState

      Get All Resource Providers
      Figure 2: Azure – Get All Resource Providers

    • Register a resource provider:
      Using the above command, we can check, if our required Resource Provider is registered or it required a registration. If our required Resource Provider not registered yet we can register it using following command. But we must have sufficient rights to register resource provider. The scope for registration is always the subscription. Our subscription must have permission to register the Resource Provider.We can see in the above figure, resource provider Microsoft.Batch has not registered yet. We can register that using the following command and the respected result can be seen in the following figure.

      Register-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch

      Registering a Resource Provider
      Figure 3: Azure – Registering a Resource Provider

      After successfully register the provider, lets check the status of the resource provider using following powershell.

      Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch

      Registered Resource Provider
      Figure 4: Azure – Registered Resource Provider

    • Get API versions of resource type:
      In this way we can use powershell to interact with resource provider. we can get much more required information like, resource types for a resource provider , API versions of resource type. following are few powershell command for the above requirement.

      (Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes.ResourceTypeName
      ((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes | Where-Object ResourceTypeName -eq batchAccounts).ApiVersions
    • Get all supported locations for a resource type:One more important point to note is, resource manager is supported in all regions, but the resources we want to deploy might not be supported in all regions. Addition to this, there may be limitations on our subscription that prevent us from using some regions that support the resource. So we can check the supported location for a resource type using following powershell command.
      ((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes | Where-Object ResourceTypeName -eq batchAccounts).Locations
      

      Supported location to a resource
      Figure 4: Azure – Supported location to a resource

  2. Azure CLI:
    As we said earlier in this blog, there are different way to work with Azure Resource Provider as we did with powershell. Now we will use Azure CLI to achieve same goal. In our one of last blog we have discussed how to start Working with Azure CLI.

    • View all resource providers in Azure :
      az provider list --query "[].{Provider:namespace, Status:registrationState}" --out table

      As we can see in the following figure, we have registered teh Microsoft.Batch resource provider in our last demo with powershell.
      Get all Resource Provider using Azure CLI
      Figure 6: Azure – Get all Resource Provider using Azure CLI

    • Register a resource provider:
      az provider register --namespace Microsoft.AlertsManagement
      az provider show --namespace Microsoft.AlertsManagement

      As we can see in the above figure, we have Microsoft.AlertsManagement resource provider, which is not registered yet. So lets proceed with this provider and register it, as in shown in the above CLI command and the result in the following figure.

      New Resource Provider resistered
      Figure 7: Azure – New Resource Provider resistered

    • Get API versions of resource type:
      az provider show --namespace Microsoft.AlertsManagement --query "resourceTypes[?resourceType=='alertsSummary'].apiVersions | [0]" --out table

      New Resource Provider resistered
      Figure 8: Azure – Version information

    • Get Supported locations information for a resource:
      az provider show --namespace Microsoft.AlertsManagement

      With the above CLI command, we have tried to find, if “Microsoft.AlertsManagement” have any locations for its any resource type. But unfortunatly, we don’t find any value there, as we can see in the following image. So here we are, using “Microsoft.Batch” provider for our demo purpose .

      No locations for the resource type
      Figure 9: Azure – No locations for the resource type

      az provider show --namespace Microsoft.Batch --query "resourceTypes[?resourceType=='batchAccounts'].locations | [0]" --out table

       Get supported location to a resourcetype
      Figure 10: Azure – Get Supported locations for a resource

We will come with one new blog, where we will describe how to communicate with Resource Provider through Azure Portal.

Hope this blog gives you a basic understanding on Azure Resource Provider.

Thanks for reading 🙂

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.

Stay tuned on Knowledge-Junction, will come up with more such articles.

Manas Ranjan Moharana

I'm a proud Indian, Son, Husband, Father, Author, Blogger, Self motivated person. I lives in Pune, Maharashtra and working for TietoEvry.pvt.ltd, to build Azure Solutions and Share Point Solutions.Microsoft certified Professional with 14 years of IT experience. Interest in learning and sharing something new, to be healthy.

You may also like...

3 Responses

  1. sujatha says:

    script to register all resource provider at a time

  1. November 30, 2018

    […] we will continue with our last post Azure – Resource Providers with PowerShell and CLI and discuss about one more approach to work with Azure Resource Provider and that is through Azure […]

  2. December 6, 2018

    […] Resource Manager service get request from API, which then authenticates and authorizes the requests. Once the request authenticated, Azure Resource Manager routes the requests to the appropriate Resource Providers. […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: