在 Windows 上安裝 Azure PowerShell
Az PowerShell 模組是匯總模組。 安裝 Az PowerShell 模組會下載一般可用的模組,並讓其 Cmdlet 可供使用。
Az PowerShell 模組的建議安裝方法和 PowerShell 版本:
- 從 PowerShell 資源庫安裝
- 搭配 PowerShell 第 7 版或更新版本使用
本文說明如何從 PowerShell 資源庫在 Windows 上安裝 Az PowerShell 模組。
先決條件
從 PowerShell 執行下列命令,以判斷您的 PowerShell 版本:
$PSVersionTable.PSVersion
判斷您是否已安裝 AzureRM PowerShell 模組:
Get-Module -Name AzureRM -ListAvailable
重要
如果您已安裝 AzureRM PowerShell 模組,請參閱 Az 和 AzureRM 共存,再繼續進行。
將 PowerShell 執行原則設定為遠端簽署或較不嚴格
檢查 PowerShell 執行原則:
Get-ExecutionPolicy -List
將 PowerShell 執行原則設定為遠端簽署:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
如需執行原則的詳細資訊,請參閱 about_Execution_Policies。
安裝
使用 Install-Module Cmdlet 來安裝 Az PowerShell 模組:
Install-Module -Name Az -Repository PSGallery -Force
更新 Az PowerShell 模組
使用 Update-Module 更新至最新版的 Az PowerShell 模組:
Update-Module -Name Az -Force
使用 Update-Module
更新 Az PowerShell 模組並不會從您的系統中移除舊版的 Az PowerShell 模組。
卸載
若要移除 Az PowerShell 模組,請參閱 卸載 Azure PowerShell 模組。
本文說明如何使用 MSI 安裝程式在 Windows 上安裝 Az PowerShell 模組。 MSI 安裝程式適用於防火牆可能會封鎖PowerShell資源庫的環境,或需要離線安裝程式。
重要
MSI 安裝選項只能用來安裝 Az PowerShell 模組,以搭配 Windows PowerShell 5.1 使用。
先決條件
從 PowerShell 執行下列命令,以判斷您的 PowerShell 版本:
$PSVersionTable.PSVersion
判斷您是否已安裝 AzureRM PowerShell 模組
Get-Module -Name AzureRM -ListAvailable
重要
如果您已安裝 AzureRM PowerShell 模組,請參閱 Az 和 AzureRM 共存,再繼續進行。
將 PowerShell 腳本執行設定為遠端簽署或較不嚴格
檢查 PowerShell 執行原則:
Get-ExecutionPolicy -List
將 PowerShell 執行原則設定為遠端簽署:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
如需執行原則的詳細資訊,請參閱 about_Execution_Policies。
安裝和更新
Azure PowerShell 的 MSI 套件可從 GitHub取得:
- 造訪 github.com/Azure/azure-powershell/releases
- 找出最新的 Az PowerShell 模組。 它們依時間順序列出,沒有名稱。 例如,
9.5.0
- 向下捲動至修補程式筆記的結尾,然後按兩下 [資產] 旁的箭號以顯示 MSI 選項。
- 點擊您選擇的 Az-Cmdlets MSI 以開始下載
安裝程式會自動移除使用 MSI 安裝的舊版 Az PowerShell 模組。 MSI 套件會在 "${env:ProgramFiles}\WindowsPowerShell\Modules"
中安裝模組
登錄
若要使用 Az PowerShell 模組開始管理 Azure 資源,請啟動 PowerShell 會話並執行 Connect-AzAccount
以登入 Azure:
Connect-AzAccount
使用您的 Azure 帳戶登入認證來登入開啟的瀏覽器視窗。
您必須針對您啟動的每個新 PowerShell 工作階段重複此步驟。 若要瞭解如何跨 PowerShell 工作階段保存 Azure 登入,請參閱 Azure PowerShell 內容物件。
故障排除
如需解決 Az PowerShell 模組常見安裝問題,請參閱 Az PowerShell 模組安裝問題疑難解答。
提供意見反應
若要提出關於 Az PowerShell 模組的問題,請參閱:在 GitHub 上提出問題
若要在 PowerShell 會話內提供意見反應,請使用 Send-Feedback Cmdlet。
後續步驟
若要深入瞭解如何使用 Az PowerShell 模組管理 Azure 資源,請參閱 開始使用 Azure PowerShell。