開始使用 Azure PowerShellGet started with Azure PowerShell

Azure PowerShell 的設計訴求是從命令列管理 Azure 資源。Azure PowerShell is designed for managing and administering Azure resources from the command line. 當您想要建置使用 Azure Resource Manager 模型的自動化工具時,就可以使用 Azure PowerShell。Use Azure PowerShell when you want to build automated tools that use the Azure Resource Manager model. 您可以在瀏覽器中嘗試將其與 Azure Cloud Shell 搭配使用,或是將其安裝在本機電腦上。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 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 China 21Vianet:For example, to sign in to Azure China 21Vianet:

Connect-AzAccount -Environment AzureChinaCloud

您會獲得在 https://microsoft.com/devicelogin 上使用的權杖。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。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. 動詞描述動作 (例如 CreateGetSetDelete),而名詞描述資源類型 (例如 AzVMAzKeyVaultCertificateAzFirewallAzVirtualNetworkGateway)。The verb describes the action (examples include Create, Get, Set, Delete) and the noun describes the resource type (examples include AzVM, AzKeyVaultCertificate, AzFirewall, AzVirtualNetworkGateway). Azure PowerShell 中的名詞一律具有前置詞:AzNouns 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

為協助您尋找常見的命令,此資料表列出可與 Get-Command 搭配的資源類型、對應 Azure PowerShell 模組和名詞前置詞: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 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