首页 > 解决方案 > Azure RM 模块在 MACOSX Catalina 上不起作用

问题描述

我正在尝试在 OSXCatalina 上的 Powershell 核心上使用 AzureRM 和 AZ 模块,但是,当我尝试使用 cmdlet Login-AzureRmAccount 或 Login-AzAccount 时。我收到以下错误。我目前正在使用 Powershell 版本 7

Login-AzureRmAccount:术语“Login-AzureRmAccount”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。

Login-AzAccount:在模块“Az.Accounts”中找到“Login-AzAccount”命令,但无法加载该模块。有关详细信息,请运行“导入模块 Az.Accounts”。

标签: macospowershellazure-rmaz

解决方案


这不是 Powershell 代码问题,这是我们在这里提供帮助的。您的问题是环境问题,因此确实应该将其移至 SuperUser 或 StackExchange。

然而,既然你在这里,这是环境问题,因为你可能没有正确/完整地设置它,如何设置和使用它在 MS Docs、MSDN 和网络上的许多其他位置都有完整的文档。快速搜索,比如使用“AzureRM osx”会显示如下内容。这些:

PowerShell、Azure 和 macOS?绝对地!

使用 macOS 上的 Azure CLI,你可以做一些有趣的事情,比如预配新的 VM 或获取它们的状态概览。但是 Azure CLI 不是 PowerShell,因此它缺少一些我非常欣赏的功能。

为了能够在 Mac 上通过 PowerShell 管理 Azure,需要执行几个步骤:

Install PowerShell
Install .NET Core
Install the AzureRm.NetCore.Preview module

brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

之后,您可以下载 .NET Core for macOS 的官方安装程序。安装后,您需要初始化一些代码。您可以使用以下命令来做到这一点:

mkdir hwapp
cd hwapp
dotnet new
dotnet restore
dotnet run

Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination /usr/local/microsoft/powershell/6.0.0-alpha.11/Modules

get-module -listAvailable

AzureRM PowerShell Mac OS X

一切都可以通过从这里安装 AzureRM 来解决:

Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2/ -ProviderName NuGet -ExcludeVersion -Destination $home/powershell/modules

Import-Module $home/powershell/modules/AzureRM.Profile.NetCore.Preview
Import-Module $home/powershell/modules/AzureRM.Resources.NetCore.Preview
Import-Module $home/powershell/modules/AzureRM.NetCore.Preview
Login-AzureRmAccount

PS。每次重新启动 PowerShell 时,都必须重新运行 Import-Module。

MacOS 上的 Powershell 和 Azure

好吧,除非你把它放在你的个人资料中。


推荐阅读