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

安装 Azure PowerShell 服务管理模块Installing the Azure PowerShell Service Management module

PowerShell 库安装 Azure PowerShell 是首选的安装方法。Installing Azure PowerShell from the PowerShell Gallery is the preferred method of installation.

步骤 1:安装 PowerShellGetStep 1: Install PowerShellGet

安装 PowerShell 库中的项需要 PowerShellGet 模块。Installing items from the PowerShell Gallery requires the PowerShellGet module. 请确保使用适当版本的 PowerShellGet 并满足其他系统要求。Make sure you have the appropriate version of PowerShellGet and other system requirements. 运行以下命令,确定是否已在系统上安装 PowerShellGet。Run the following command to see if you have PowerShellGet installed on your system.

Get-InstalledModule PowerShellGet -AllVersions | Select-Object Name,Version,Path

应会看到类似于下面的信息:You should see something similar to the following output:

Name          Version Path
----          ------- ----
PowerShellGet 1.0.0.1 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PowerShellGet.psd1

如果没有安装 PowerShellGet,请参阅如何获取 PowerShellGetIf you do not have PowerShellGet installed, see the How to get PowerShellGet.

步骤 2:安装 Azure PowerShellStep 2: Install Azure PowerShell

在以管理员身份运行的 Windows PowerShell 控制台中运行以下命令:Run the following command from the Windows PowerShell console running as Administrator:

Install-Module Azure

Azure 模块是 Azure 资源管理器 cmdlet 的汇总模块。The Azure module is a rollup module for the Azure Resource Manager cmdlets. 安装 AzureRM 模块时,将从 PowerShell 库下载并安装先前尚未安装的其他所有 Azure 模块。When you install the AzureRM module, any other Azure modules that have not previously been installed will be downloaded and installed from the PowerShell Gallery.

Azure 服务管理模块与 Azure PowerShell Resource Manager 模块共享依赖项。The Azure Service Management module shares dependencies with the Azure PowerShell Resource Manager modules. 如果已安装 Azure PowerShell Resource Manager 模块,需在安装命令中添加 -AllowClobber 参数。If you have installed the Azure PowerShell Resource Manager modules, you will need to add the -AllowClobber parameter to the install command. 这样,便可以更新现有的共享依赖项。This allows this existing shared dependencies to be updated. 如果不提供此参数,模块安装会失败。Without this parameter, installation of the module fails.

Install-Module Azure -AllowClobber

安装此模块后,可运行以下命令导入此模块:After you install this module, you can import the module by running the following command:

Import-Module Azure

使用 cmdletTo use the cmdlets

若要开始使用 Azure 服务管理 cmdlet,请先登录到 Azure 帐户。To start working with the Azure Service Management cmdlets, first log on to your Azure account. 若要登录到帐户,请运行以下命令:To log on to your account, run the following command:

Add-AzureAccount

登录到 Azure 后,Azure PowerShell 将为给定的会话创建上下文。After logging into Azure, Azure PowerShell creates a context for the given session. 该上下文包含用于该会话中的所有 cmdlet 的 Azure PowerShell 环境、帐户、租户和订阅。That context contains the Azure PowerShell environment, account, tenant, and subscription that will be used for all cmdlets within that session. 现已准备就绪,可以使用下面的模块。Now you are ready to use the modules below.

Azure 服务管理 cmdletAzure Service Management cmdlets

Azure PowerShell 模块经常更新。Azure PowerShell modules are updated frequently. 如果发现 cmdlet 联机帮助包含模块中所不包含的 cmdlet 或参数,请下载并安装最新版本的模块。If you notice that the online cmdlet help includes cmdlets or parameters that are not in your module, download and install the latest version of the module. 若要查找模块版本,请键入:(Get-InstalledModule Azure).VersionTo find the version of your module, type: (Get-InstalledModule Azure).Version.

有关可帮助自动完成 Azure 中某些常见任务的示例脚本,请参阅 Windows Azure 脚本中心For sample scripts that can help you automate some of the common tasks in Azure, see the Windows Azure Script Center.

有关安装、学习、使用和自定义 Windows PowerShell 的一般信息,请参阅使用 Windows PowerShell 编写脚本For general information about installing, learning, using, and customizing Windows PowerShell, see Scripting with Windows PowerShell.

如何获取 PowerShellGetHow to get PowerShellGet

OS 版本。OS Version 安装说明Install instructions
我使用的是 Windows 10 或 Windows Server 2016I have Windows 10 or Windows Server 2016 内置在 OS 随附的 Windows Management Framework (WMF) 5.0 中Built into Windows Management Framework (WMF) 5.0 included in the OS
我想要升级到 PowerShell 5I want to upgrade to PowerShell 5 安装最新版本的 WMFInstall the latest version of WMF
我正在运行某个包含 PowerShell 3 或 PowerShell 4 的 Windows 版本I am running on a version of Windows with PowerShell 3 or PowerShell 4 获取 PackageManagement 模块Get the PackageManagement modules

检查 Azure PowerShell 的版本Checking the version of Azure PowerShell

虽然我们建议尽早升级到最新版本,但仍然支持多个 Azure PowerShell 版本。Although we encourage you to upgrade to the latest version as early as possible, several versions of Azure PowerShell are support. 若要确定安装的 Azure PowerShell 版本,请从命令行运行 Get-InstalledModule AzureTo determine the version of Azure PowerShell you have installed, run Get-InstalledModule Azure from your command line.

Get-InstalledModule Azure -AllVersions | Select-Object Name,Version,Path