你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Az PowerShell 模块是一个汇总模块。 安装 Az PowerShell 模块会下载正式发布的模块并使其 cmdlet 可供使用。
适用于 Az PowerShell 模块的建议安装方法和 PowerShell 版本:
- 从 PowerShell 库安装
- 与 PowerShell 版本 7 或更高版本配合使用
本文介绍如何从 PowerShell 库在 Windows 上安装 Az PowerShell 模块。
先决条件
从 PowerShell 运行以下命令,确定 PowerShell 版本:
$PSVersionTable.PSVersion确定是否安装了 AzureRM PowerShell 模块:
Get-Module -Name AzureRM -ListAvailable重要
如果已安装 AzureRM PowerShell 模块,请参阅 Az 和 AzureRM 共存 ,然后再继续作。
将 PowerShell 执行策略设置为远程签名或限制更少
检查 PowerShell 执行策略:
Get-ExecutionPolicy -List将 PowerShell 执行策略设置为远程签名:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
有关执行策略的详细信息,请参阅 about_Execution_Policies。
Installation
使用 Install-Module cmdlet 安装 Az PowerShell 模块:
Install-Module -Name Az -Repository PSGallery -Force
更新 Az PowerShell 模块
使用 Update-Module 更新到最新版本的 Az PowerShell 模块:
Update-Module -Name Az -Force
使用更新 Az PowerShell 模块 Update-Module 不会从系统中删除旧版 Az PowerShell 模块。
卸载
若要删除 Az PowerShell 模块,请参阅 “卸载 Azure PowerShell 模块”。
本文介绍如何使用 MSI 安装程序在 Windows 上安装 Az PowerShell 模块。 MSI 安装程序适用于防火墙可能阻止 PowerShell 库或需要脱机安装程序的环境。
重要
MSI 安装选项只能用于安装用于 Windows PowerShell 5.1 的 Az PowerShell 模块。
先决条件
从 PowerShell 运行以下命令,确定 PowerShell 版本:
$PSVersionTable.PSVersion确定是否已安装 AzureRM PowerShell 模块
Get-Module -Name AzureRM -ListAvailable重要
如果已安装 AzureRM PowerShell 模块,请参阅 Az 和 AzureRM 共存 ,然后再继续作。
将 PowerShell 脚本执行设置为远程签名或限制较小
检查 PowerShell 执行策略:
Get-ExecutionPolicy -List将 PowerShell 执行策略设置为远程签名:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
有关执行策略的详细信息,请参阅 [about_Execution_Policies][execution-poliicies]。
安装和更新
Azure PowerShell 的 MSI 包可从 [GitHub][azps-github]获取:
- 访问 github.com/Azure/azure-powershell/releases
- 找到最新的 Az PowerShell 模块。 它们按时间顺序列出,没有名称。 例如:
13.3.0 - 向下滚动到修补笔记的末尾,然后选择“资产”旁边的箭头以显示 MSI 选项。
- 选择所选的 Az-Cmdlets MSI 以开始下载
安装程序会自动删除使用 MSI 安装的旧版 Az PowerShell 模块。 MSI 包将模块安装到 "${env:ProgramFiles}\WindowsPowerShell\Modules"
登录
若要开始使用 Az PowerShell 模块管理 Azure 资源,请启动 PowerShell 会话并运行 Connect-AzAccount 以登录到 Azure:
Connect-AzAccount
使用 Azure 帐户登录凭据登录到打开的浏览器窗口。
对于启动的每个新的 PowerShell 会话,需要重复此步骤。 若要了解如何跨 PowerShell 会话保留 Azure 登录,请参阅 Azure PowerShell 上下文对象。
Troubleshooting
有关 Az PowerShell 模块常见安装问题的解决方案,请参阅 对 Az PowerShell 模块的安装问题进行故障排除。
提供反馈
若要提交有关 Az PowerShell 模块的问题,请参阅: 在 GitHub 上提出问题
若要在 PowerShell 会话中提供反馈,请使用 Send-Feedback cmdlet。
后续步骤
若要详细了解如何使用 Az PowerShell 模块管理 Azure 资源,请参阅 Azure PowerShell 入门。