首页 > 解决方案 > 术语“Register-AzResourceProvider”未被识别为 cmdlet 的名称

问题描述

嗨,我正在尝试自学 Azure,我正在遵循本指南:https ://docs.microsoft.com/en-us/learn/modules/intro-to-governance/2-azure-policy 。我在 Windows 10 上$PSVersionTable.PSEdition=Desktop我向 Microsoft 支持发送了消息,但没有人回复。当我尝试跑步时

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

我明白了

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.

我已检查是否安装了 Azure powershell

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
}

对此的任何帮助将不胜感激。

标签: azurepowershellazure-powershell

解决方案


要解决此问题,请尝试按照以下步骤操作。

1.通过打开一个新的powershell会话Run as administrator,然后运行下面的命令。

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

2.安装模块后,关闭管理员会话并打开一个新的普通powershell会话,然后登录您的用户帐户,该帐户有权注册提供者,例如Owner订阅。

Connect-AzAccount

3.然后注册提供者。

Register-AzResourceProvider -ProviderNamespace 'Microsoft.PolicyInsights'

在此处输入图像描述

注意:如果问题仍然存在,请使用Get-Module检查Az.Resources模块是否在此powershell会话中导入(通常会自动导入),如果没有,您可以使用Import-Module -Name Az.Resources -Force手动导入。


推荐阅读