你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
注释
本文档中引用的 cmdlet 用于管理使用 Azure Service Manager (ASM) API 的旧式 Azure 资源。 创建新资源时,建议不要使用旧的 PowerShell 模块,因为计划将停用 ASM。 有关详细信息,请参阅 Azure Service Manager 停用。
Az PowerShell 模块是建议用于管理 PowerShell 的 Azure 资源管理器 (ARM) 资源的 PowerShell 模块。
Azure PowerShell 服务管理模块是汇总模块。 安装 Azure PowerShell 服务管理模块会下载用于管理使用服务管理 API 的旧版 Azure 资源的正式版模块,并使其 cmdlet 可供使用。
先决条件
重要
Azure PowerShell 服务管理模块仅适用于 Windows PowerShell。 它与 PowerShell 版本 6 或更高版本不兼容,并且无法在 Linux 或 macOS 上运行。
从 PowerShell 运行以下命令,确定 PowerShell 版本:
$PSVersionTable.PSVersion
将 PowerShell 执行策略设置为远程签名的或较不严格
检查 PowerShell 执行策略:
Get-ExecutionPolicy -List
将 PowerShell 执行策略设置为远程签名:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
有关执行策略的详细信息,请参阅 about_Execution_Policies。
安装
使用 Install-Module cmdlet 安装 Azure PowerShell 服务管理模块:
Install-Module -Name Azure, Azure.Storage -Repository PSGallery -AllowClobber -Force
Azure PowerShell 服务管理模块与 Azure PowerShell 资源管理器模块共享依赖项。 如果已安装 Azure PowerShell 资源管理器模块,则需要如上一命令所示的 AllowClobber 参数。 这允许更新现有的共享依赖项。 如果没有此参数,模块安装将失败。
安装 Azure PowerShell 服务管理模块后,导入该模块:
Import-Module -Name Azure
登录
若要开始使用 Azure PowerShell 服务管理模块管理旧版 Azure 资源,请启动 PowerShell 会话并运行 Add-AzureAccount 以登录到 Azure:
Add-AzureAccount
登录到 Azure 后,Azure PowerShell 服务管理模块将为给定会话创建上下文。 该上下文包含用于该会话内所有 cmdlet 的 Azure 环境、帐户、租户和订阅。
故障排除
如果收到错误“版本 为”4.3.0“的指定模块”Azure.Storage“未加载,因为未在任何模块目录中找到有效的模块文件。”,则需要安装 Azure.Storage PowerShell 模块:
Install-Module -Name Azure.Storage -Repository PSGallery -AllowClobber -Force
如果收到错误“在 模块”PowerShellGet“中找到”Install-Module“命令,但无法加载模块。”,则需要将 PowerShell 执行策略设置为远程签名或限制更少:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
另请参阅
有关 Azure PowerShell 服务管理模块中的命令的详细信息,请参阅 cmdlet 参考文档。