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

Azure PowerShell 入门Get started with Azure PowerShell

Azure PowerShell 用于从命令行管理 Azure 资源。Azure PowerShell is designed for managing and administering Azure resources from the command line. 若要生成使用 Azure 资源管理器模型的自动化工具,请使用 Azure PowerShell。Use Azure PowerShell when you want to build automated tools that use the Azure Resource Manager model. 在浏览器中配合 Azure Cloud Shell 试用 Azure PowerShell,或者将它安装在本地计算机上。Try it out in your browser with Azure Cloud Shell, or install on your local machine.

本文将帮助你开始使用 Azure PowerShell,并讲解与其相关的核心概念。This article helps you get started with Azure PowerShell and teaches the core concepts behind it.

在 Azure Cloud Shell 中安装或运行Install or run in Azure Cloud Shell

Azure PowerShell 的最简单入门方法是在 Azure Cloud Shell 环境中试用它。The easiest way to get started with Azure PowerShell is by trying it out in an Azure Cloud Shell environment. 若要配合 Cloud Shell 开始运行 Azure PowerShell,请参阅 Azure Cloud Shell 中的 PowerShell 快速入门To get up and running with Cloud Shell, see Quickstart for PowerShell in Azure Cloud Shell. Cloud Shell 在 Linux 容器中运行 PowerShell 6,因此,特定于 Windows 的功能不可用。Cloud Shell runs PowerShell 6 on a Linux container, so Windows-specific functionality isn't available.

如果你已准备好在本地计算机上安装 Azure PowerShell,请遵照安装 Azure PowerShell 模块中的说明。When you're ready to install Azure PowerShell on your local machine, follow the instructions in Install the Azure PowerShell module.

登录 AzureSign in to Azure

使用 Connect-AzAccount cmdlet 以交互方式登录。Sign in interactively with the Connect-AzAccount cmdlet. 如果使用 Cloud Shell,请跳过此步骤:Azure Cloud Shell 会话已针对启动 Cloud Shell 会话的环境、订阅和租户进行身份验证。Skip this step if you use Cloud Shell: Your Azure Cloud Shell session is already authenticated for the environment, subscription, and tenant that launched the Cloud Shell session.

Connect-AzAccount

如果你不在美国区域,请使用 -Environment 参数登录。If you're in a non-US region, use the -Environment parameter to sign in. 使用 Get-AzEnvironment cmdlet 获取所在区域的环境名称。Get the name of the environment for your region by using the Get-AzEnvironment cmdlet. 例如,若要登录到 Azure 中国世纪互联:For example, to sign in to Azure China 21Vianet:

Connect-AzAccount -Environment AzureChinaCloud

在 PowerShell 5.1 环境中,将显示一个登录对话框,用于为 Azure 帐户提供用户名和密码。In PowerShell 5.1 environments, you'll get a sign-in dialog to provide a username and password for your Azure account. 在 PowerShell 的每个其他版本上,你将获得可在 [https://microsoft.com/devicelogin ] 上使用的令牌。On every other version of PowerShell, you'll get a token to use on [https://microsoft.com/devicelogin]. 在浏览器中打开此页面,输入令牌,使用 Azure 帐户凭据登录,然后对 Azure PowerShell 进行授权。Open this page in your browser and enter the token, then sign in with your Azure account credentials and authorize Azure PowerShell.

登录后,你会看到指明你的哪个 Azure 订阅处于活动状态的信息。After signing in, you'll see information indicating which of your Azure subscriptions is active. 如果你的帐户中有多个 Azure 订阅,并且你希望选择其他订阅,请通过 Get-AzSubscription 获取可用订阅并将 Set-AzContext cmdlet 与订阅 ID 配合使用。If you have multiple Azure subscriptions in your account and want to select a different one, get your available subscriptions with Get-AzSubscription and use the Set-AzContext cmdlet with your subscription ID. 有关在 Azure PowerShell 中管理 Azure 订阅的详细信息,请参阅使用多个 Azure 订阅For more information about managing your Azure subscriptions in Azure PowerShell, see Use multiple Azure subscriptions.

登录后,使用 Azure PowerShell cmdlet 访问和管理订阅中的资源。Once signed in, use the Azure PowerShell cmdlets to access and manage resources in your subscription. 若要详细了解登录过程和身份验证方法,请参阅使用 Azure PowerShell 登录To learn more about the sign-in process and authentication methods, see Sign in with Azure PowerShell.

查找命令Find commands

Azure PowerShell cmdlet 遵循 PowerShell 的标准命名约定 VERB-NOUNAzure PowerShell cmdlets follow a standard naming convention for PowerShell, VERB-NOUN. 谓词描述操作(例如 NewGetSetRemove),名词描述资源类型(例如 AzVMAzKeyVaultCertificateAzFirewallAzVirtualNetworkGateway)。The verb describes the action (examples include New, Get, Set, Remove) and the noun describes the resource type (examples include AzVM, AzKeyVaultCertificate, AzFirewall, AzVirtualNetworkGateway). Azure PowerShell 中的名词始终以 Az 前缀开头。Nouns in Azure PowerShell always start with the prefix Az. 有关标准谓词的完整列表,请参阅 PowerShell 命令的已批准谓词For the full list of standard verbs, see Approved verbs for PowerShell Commands.

了解名词、谓词和 Azure PowerShell 模块有助于使用 Get-Command cmdlet 查找命令。Knowing the nouns, verbs, and the Azure PowerShell modules available help you find commands with the Get-Command cmdlet. 例如,若要查找使用 Get 谓词的所有 VM 相关命令:For example, to find all VM-related commands that use the Get verb:

Get-Command -Verb Get -Noun AzVM* -Module Az.Compute

为帮助你查找常用命令,下表列出了资源类型、相应的 Azure PowerShell 模块,以及要在 Get-Command 中使用的名词前缀:To help you find common commands, this table lists the resource type, corresponding Azure PowerShell module, and noun prefix to use with Get-Command:

资源类型Resource type Azure PowerShell 模块Azure PowerShell module 名词前缀Noun prefix
资源组Resource group Az.ResourcesAz.Resources AzResourceGroup
虚拟机Virtual machines Az.ComputeAz.Compute AzVM
存储帐户Storage accounts Az.StorageAz.Storage AzStorageAccount
Key VaultKey Vault Az.KeyVaultAz.KeyVault AzKeyVault
Web 应用程序Web applications Az.WebsitesAz.Websites AzWebApp
SQL 数据库SQL databases Az.SqlAz.Sql AzSqlDatabase

有关 Azure PowerShell 中的模块的完整列表,请参阅 GitHub 上的 Azure PowerShell 模块列表For a full list of the modules in Azure PowerShell, see the Azure PowerShell modules list hosted on GitHub.

使用快速入门和教程了解 Azure PowerShell 基础知识Learn Azure PowerShell basics with quickstarts and tutorials

若要开始使用 Azure PowerShell,请尝试学习有关设置虚拟机及其查询方法的深入教程。To get started with Azure PowerShell, try an in-depth tutorial for setting up virtual machines and learning how to query them.

此外,其他流行的 Azure 服务也提供了 Azure PowerShell 快速入门:There are also Azure PowerShell quickstarts for other popular Azure services:

后续步骤Next steps