Fixing The subscription is not registered to use namespace ‘Microsoft.xxx’

When you automatically deploy to a brand new subscription, for example using VSTS, not all resource providers are registered.

For example when you try to deploy Azure EventHub you will get the following exception:

The subscription is not registered to use namespace ‘Microsoft.EventHub’

After adding resources by hand in the Azure Portal the corresponding resource providers are registered, which is the reason why you will not always see this exception.
Instead of adding resources by hand the first time, an alternative is to register the resource providers with powershell.

You can register the single resource provider that you need with the following line:

Register-AzureRmResourceProvider -ProviderNamespace “Microsoft.EventHub”

If you like, you can also register all resource providers at once.
This can be done with the following script:

Select-AzureRmSubscription -SubscriptionName “”

$providerNamespaces = @(Get-AzureRmResourceProvider -ListAvailable) | ? {$_.RegistrationState -eq “NotRegistered” } | select ProviderNamespace

$providerNamespaces | foreach {
write-host $_.ProviderNamespace
Register-AzureRmResourceProvider -ProviderNamespace $_.ProviderNamespace
}
write-host “Finished!”

(make sure you are using the latest Azure PowerShell version. Otherwise you will be asked to confirm for every registration (which you can prevent by adding -Force))

[Update on 12 April 2019]

Hereby also the Azure CLI version of the script in bash

#!/usr/bin/env bash

SUBSCRIPTIONNAMEORID=YOURSUBSCRIPTIONID
echo $SUBSCRIPTIONNAMEORID

az account set --subscription $SUBSCRIPTIONNAMEORID

NOTREGISTEREDNAMESPACES=$(az provider list --query "[?registrationState=='NotRegistered'].namespace" -o tsv)

for NAMESPACE in $NOTREGISTEREDNAMESPACES
do
echo "Register: $NAMESPACE"
  az provider register --namespace $NAMESPACE
done

echo 'Finished!'

 

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit /  Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s

Deze site gebruikt Akismet om spam te bestrijden. Ontdek hoe de data van je reactie verwerkt wordt.