分享

使用 PowerShellGet 在 Windows 上安装 Azure PowerShell | Microsoft Docs

 ar135 2018-08-28

您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs..

使用 PowerShellGet 在 Windows 上安装 Azure PowerShell

  • 作者
    • Stephen Tramer
    • olprod

本文介绍了在 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 的版本,请运行以下命令:

PowerShell
$PSVersionTable.PSVersion

如果版本已过时,请参阅升级现有的 Windows PowerShell

重要

本文档中介绍的模块 AzureRM 使用 .NET Framework。 这使得它与使用 .NET Core 的 PowerShell 6.0 兼容。 如果使用的是 PowerShell 6.0,请遵循适用于 macOS 和 Linux 的安装说明

安装 Azure Powershell 模块

需要提升的权限才能通过 PowerShell 库安装模块。 若要安装 Azure PowerShell,请在已提升权限的会话中运行以下命令:

PowerShell
Install-Module -Name AzureRM

备注

如果使用的 NuGet 版本低于 2.8.5.201,系统会提示下载并安装最新版本的 NuGet。

默认情况下,PowerShell 库未配置为 PowerShellGet 的受信任存储库。 首次使用 PSGallery 时会看到以下提示:

output
Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change
its 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"):

请回答 YesYes to All 继续安装。

AzureRM 模块是 Azure PowerShell cmdlet 的汇总模块。 安装它时,系统会下载所有可用的 Azure 资源管理器模块并使其 cmdlet 可供使用。

登录

若要开始使用 Azure PowerShell,需使用 Import-Module cmdlet 将 AzureRM 加载到当前的 PowerShell 会话中,然后使用 Azure 凭据登录。

PowerShell
# Import the module into the PowerShell session
Import-Module AzureRM
# Connect to Azure with an interactive dialog for sign-in
Connect-AzureRmAccount

需对每个启动的新 PowerShell 会话重复这些步骤。 自动导入 AzureRM 模块要求设置 PowerShell 配置文件,详见关于配置文件 若要了解如何跨会话保持 Azure 登录状态,请参阅跨 PowerShell 会话保持用户凭据

更新 Azure PowerShell 模块

可以通过运行 Update-Module 来更新 Azure PowerShell 安装。 此命令不卸载以前的版本。

PowerShell
Update-Module -Name AzureRM

若要从系统中删除旧版 Azure PowerShell,请参阅卸载 Azure PowerShell 模块

使用多个版本的 Azure PowerShell

可以安装多个版本的 Azure PowerShell。 如果使用本地 Azure Stack 资源、运行不能更新到 PowerShell 5.0 的旧版 Windows,或者使用 Azure 经典部署模型,则可能需要多个版本。 若要安装旧版本,请在安装时提供 -RequiredVersion 参数。

PowerShell
# Install version 1.2.9 of Azure PowerShell
Install-Module -Name AzureRM -RequiredVersion 1.2.9

加载 Azure PowerShell 模块时,默认加载最新版本。 若要加载另一版本,请提供 -RequiredVersion 参数。

PowerShell
# Load version 1.2.9 of Azure PowerShell
Import-Module -Name AzureRM -RequiredVersion 1.2.9

提供反馈

如果在使用 Azure Powershell 时发现 Bug,请在 GitHub 上提出问题 若要从命令行提供反馈,请使用 Send-Feedback cmdlet。

后续步骤

若要开始使用 Azure PowerShell,请参阅 Azure PowerShell 入门,详细了解此模块及其功能。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多