Search code examples
azurepowershellazure-powershell

The term 'Register-AzResourceProvider' is not recognized as the name of a cmdlet


Hi I am trying to teach myself Azure and I'm following this guide: https://learn.microsoft.com/en-us/learn/modules/intro-to-governance/2-azure-policy. I'm on a windows 10 with $PSVersionTable.PSEdition = Desktop I messaged Microsoft support, but no one has responded. When I try to run

# Register the resource provider if it's not already registered
Register-AzResourceProvider -ProviderNamespace 'Microsoft.PolicyInsights'

I get

Register-AzResourceProvider : The term 'Register-AzResourceProvider' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.

I've checked off having Azure powershell installed

if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) {
    Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
      'Az modules installed at the same time is not supported.')
} else {
    Install-Module -Name Az -AllowClobber -Scope CurrentUser
}

Any help with this would be greatly appreciated.


Solution

  • To solve the issue, try to follow the steps below.

    1.Open a new powershell session via Run as administrator, then run the command below.

    Install-Module -Name Az -AllowClobber -Scope AllUsers -Force 
    

    2.After installing the module, close the administrator session and open a new normal powershell session, then login your user account which has the permission to register the provider, e.g. Owner of the subscription.

    Connect-AzAccount
    

    3.Then register the provider.

    Register-AzResourceProvider -ProviderNamespace 'Microsoft.PolicyInsights'
    

    enter image description here

    Note: If the issue is still existing, use Get-Module to check if the Az.Resources module was imported in this powershell session(normally it will be imported automatiocally), if not, you could use Import-Module -Name Az.Resources -Force to import it manually.