这不是 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
好吧,除非你把它放在你的个人资料中。