Azure PowerShell 是一個強大的工具,可以直接從 PowerShell 管理與管理 Azure 資源。 它非常適合建立自動化工作流程並使用 Azure Resource Manager 模型管理資源。 你可以用瀏覽器的 Azure Cloud Shell 試試看,或是在本地安裝在你的電腦上。
本文將幫助你入門使用 Azure PowerShell,並教授其核心概念。
在 Azure Cloud Shell 中安裝或執行
嘗試 Azure PowerShell 最簡單的方法是透過 Azure Cloud Shell,這是一個無需安裝的瀏覽器環境。 要開始,請參考 Get Start with Azure Cloud Shell。 Cloud Shell 在 Linux 容器上執行 PowerShell,因此沒有 Windows 專屬的功能。
當您準備好在本地安裝Azure PowerShell時,請依照如何安裝 Azure PowerShell 中的步驟操作。
登入 Azure
若要登入,請使用 Connect-AzAccount Cmdlet。 如果你使用 Cloud Shell,可以跳過這個步驟,因為你已經為環境、訂閱和租戶認證過。
Connect-AzAccount
Important
自 2025 年 9 月起,Azure PowerShell 在使用 Microsoft Entra ID 使用者身份登入時,將要求多重驗證(MFA)。 此變更可增強安全性,但可能會影響依賴使用者名稱和密碼驗證的自動化工作流程。 欲了解更多資訊,請參閱多重身份認證對自動化情境中Azure PowerShell的影響。
對於需要特定合規的區域環境,例如Azure China 21Vianet,請使用 Environment參數:
Connect-AzAccount -Environment AzureChinaCloud
Azure PowerShell 在 Windows 系統上預設使用 Web Account Manager (WAM) 進行認證,而其他平台則使用瀏覽器登入。 如需詳細資訊,請參閱 Web 帳戶管理員 (WAM)。
如果您有權存取多個訂閱,系統會在登入時提示您選擇一個訂閱。 在 登入體驗中深入瞭解此過程。
登入後,你可以使用 Azure PowerShell cmdlets 來管理資源。 欲了解更多認證資訊,請參閱 以 Azure PowerShell 登入。
尋找命令
Azure PowerShell cmdlets 遵循標準的 PowerShell 命名規則 Verb-Noun。 動詞描述動作,例如New、Get、Set和Remove,而名詞代表資源類型,例如AzVM、AzKeyVaultCertificate、AzFirewall和AzVirtualNetworkGateway。 Azure PowerShell 中的名詞以前綴 Az 開頭。
若要探索命令,請使用 Get-Command Cmdlet。 例如,若要列出與虛擬機器相關的所有命令:
Get-Command -Verb Get -Noun AzVM* -Module Az.Compute
以下是常見資源及其相關模組的快速參考表:
| 資源類型 | Azure PowerShell Module | 名詞前綴 |
|---|---|---|
| 資源群組 | Az.Resources | AzResourceGroup |
| 虛擬機器 | Az.Compute | AzVM |
| 記憶體帳戶 | Az.Storage | AzStorageAccount |
| 金鑰保存庫 | Az.KeyVault | AzKeyVault |
| Web 應用程式 | Az.Websites | AzWebApp |
| SQL 資料庫 | Az.Sql | AzSql資料庫 |
欲了解完整的Azure PowerShell模組清單,請參閱GitHub主機上的Azure PowerShell模組列表。
數據採集
預設情況下,Azure PowerShell 會收集遙測資料,透過識別使用模式與問題來提升使用者體驗。 不會收集任何私人或個人資料。 不過,如果您偏好,也可以使用 Disable-AzDataCollection cmdlet 來選擇退出。 如需詳細資訊,請參閱我們的 隱私權聲明。
快速入門和教學課程
透過我們的指導教學,親手操作 Azure PowerShell:
- 建立儲存體帳戶
- 將物件傳送到/從Azure Blob 儲存
- 在 Azure Key Vault 中建立並檢索秘密
- 建立Azure SQL資料庫與防火牆
在 Azure 容器執行個體 - 建立虛擬機器規模集
- 建立標準負載平衡器
下一步
探索更多 Azure PowerShell 功能:
- 使用 Azure PowerShell 登入
用 Azure PowerShell 用 Azure PowerShell
如需更多幫助,請與社區聯繫: