您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.
本文介绍了在 Windows 环境中使用 PowerShellGet 安装 Azure PowerShell 模块的步骤。 PowerShellGet 和模块管理是安装 Azure PowerShell 的首选方法,但是如果希望使用 Web 平台安装程序或 MSI 包进行安装,请参阅其他安装方法。
有关如何在其他平台上安装 Azure PowerShell 的说明,请参阅在 macOS 和 Linux 上安装和配置 Azure PowerShell。
此版 Azure PowerShell 不支持 Azure 经典部署模型。 若要获取经典部署的支持,请按安装 Azure PowerShell 服务管理模块中的说明操作。
从 Azure PowerShell 版本 6.0 开始,Azure PowerShell 需要 PowerShell 版本 5.0。 若要查看在计算机上运行的 PowerShell 的版本,请运行以下命令:
$PSVersionTable.PSVersion
如果版本已过时,请参阅升级现有的 Windows PowerShell。
重要
本文档中介绍的模块 AzureRM 使用 .NET Framework。 这使得它与使用 .NET Core 的 PowerShell 6.0 兼容。 如果使用的是 PowerShell 6.0,请遵循适用于 macOS 和 Linux 的安装说明。
需要提升的权限才能通过 PowerShell 库安装模块。 若要安装 Azure PowerShell,请在已提升权限的会话中运行以下命令:
Install-Module -Name AzureRM
备注
如果使用的 NuGet 版本低于 2.8.5.201,系统会提示下载并安装最新版本的 NuGet。
默认情况下,PowerShell 库未配置为 PowerShellGet 的受信任存储库。 首次使用 PSGallery 时会看到以下提示:
Untrusted repositoryYou are installing the modules from an untrusted repository. If you trust this repository, changeits InstallationPolicy value by running the Set-PSRepository cmdlet.Are you sure you want to install the modules from 'PSGallery'?[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
请回答 Yes
或 Yes to All
继续安装。
AzureRM
模块是 Azure PowerShell cmdlet 的汇总模块。 安装它时,系统会下载所有可用的 Azure 资源管理器模块并使其 cmdlet 可供使用。
若要开始使用 Azure PowerShell,需使用 Import-Module cmdlet 将 AzureRM
加载到当前的 PowerShell 会话中,然后使用 Azure 凭据登录。
# Import the module into the PowerShell sessionImport-Module AzureRM# Connect to Azure with an interactive dialog for sign-inConnect-AzureRmAccount
需对每个启动的新 PowerShell 会话重复这些步骤。 自动导入 AzureRM
模块要求设置 PowerShell 配置文件,详见关于配置文件。若要了解如何跨会话保持 Azure 登录状态,请参阅跨 PowerShell 会话保持用户凭据。
可以通过运行 Update-Module 来更新 Azure PowerShell 安装。 此命令不卸载以前的版本。
Update-Module -Name AzureRM
若要从系统中删除旧版 Azure PowerShell,请参阅卸载 Azure PowerShell 模块。
可以安装多个版本的 Azure PowerShell。 如果使用本地 Azure Stack 资源、运行不能更新到 PowerShell 5.0 的旧版 Windows,或者使用 Azure 经典部署模型,则可能需要多个版本。 若要安装旧版本,请在安装时提供 -RequiredVersion
参数。
# Install version 1.2.9 of Azure PowerShellInstall-Module -Name AzureRM -RequiredVersion 1.2.9
加载 Azure PowerShell 模块时,默认加载最新版本。 若要加载另一版本,请提供 -RequiredVersion
参数。
# Load version 1.2.9 of Azure PowerShellImport-Module -Name AzureRM -RequiredVersion 1.2.9
如果在使用 Azure Powershell 时发现 Bug,请在 GitHub 上提出问题。若要从命令行提供反馈,请使用 Send-Feedback cmdlet。
若要开始使用 Azure PowerShell,请参阅 Azure PowerShell 入门,详细了解此模块及其功能。
联系客服