如何在 PowerShell 7 中使用 AzureRm 模块?

How to use AzureRm module with PowerShell 7?

上下文

我刚刚安装了 PowerShell 7。我正在尝试 运行 我的工作测试 Azure 相关脚本...所以我安装并导入了 AzureAd 和 AzureRM 模块。

尝试登录 Connect-AzureADConnect-AzureRmAccount 时都出现以下错误(继续阅读)

Could not load type 'System.Security.Cryptography.SHA256Cng'

好的,这是因为 Azure 模块正在寻找 API,这在 .NET Core 中不可用,所以我使用 Import-Module-UseWindowsPowerShell 参数,这解决了问题但仅适用于 AzureAD 模块

问题

对于命令 Import-Module AzureRm -UseWindowsPowerShell 我收到以下错误消息:

Import-Module: Failed to generate proxies for remote module 'AzureRM'. Running the Get-Command command in a remote session returned no results.

所以我还是不能用Connect-AzureRmAccount有什么想法吗?

AzureRm 与 PowerShell 7 不兼容,已弃用且不会更新。

您的选择是使用Az模块,只需卸载AzureRm模块并安装Az模块。

Install-Module -Name Az -Force

有关详细信息,请参阅 Introducing the new Azure PowerShell Az module

然后使用Connect-AzAccount登录,如果您不想更改使用AzureRm命令的现有脚本,只需在所有命令之前使用Enable-AzureRmAlias即可。