术语“Register-AzResourceProvider”未被识别为 cmdlet 的名称

Eva*_*tis 0 powershell azure azure-powershell

您好,我正在尝试自学 Azure,并且正在遵循本指南: https: //learn.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'
Run Code Online (Sandbox Code Playgroud)

我明白了

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.
Run Code Online (Sandbox Code Playgroud)

我已检查是否已安装 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
}
Run Code Online (Sandbox Code Playgroud)

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

Joy*_*ang 6

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

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

Install-Module -Name Az -AllowClobber -Scope AllUsers -Force 
Run Code Online (Sandbox Code Playgroud)

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

Connect-AzAccount
Run Code Online (Sandbox Code Playgroud)

3.然后注册提供商。

Register-AzResourceProvider -ProviderNamespace 'Microsoft.PolicyInsights'
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

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