Share via


使用 PowerShellGet 在 Windows 上安裝 Azure PowerShell

警告

自 2024 年 2 月 29 日起,AzureRM PowerShell 模組已正式淘汰。 建議使用者從 AzureRM 遷移至 Az PowerShell 模組,以確保持續支援和更新。

雖然 AzureRM 模組可能仍可運作,但不再維護或支援它,但會根據用戶的判斷權和風險放置任何繼續使用。 如需轉換至 Az 模組的指引,請參閱我們的 移轉資源

本文說明使用 PowerShellGet 安裝適用於 Windows PowerShell 5.x 的 Azure PowerShell 模組的步驟。 PowerShellGet 和模組管理是安裝 Azure PowerShell 的慣用方式,但如果您想要使用 Web Platform Installer 或 MSI 套件進行安裝,請參閱 其他安裝方法

此版本的 Azure PowerShell 不支援 Azure 傳統部署模型。 如需傳統部署的支援,請遵循安裝 Azure PowerShell 服務管理模組中的指示。

重要

macOS 或 Linux 不支援 AzureRM 模組。 若要在這些平臺上使用 Azure PowerShell Cmdlet, 請安裝 Az 模組

需求

從 Azure PowerShell 6.0 版開始,Azure PowerShell 需要 PowerShell 5.0 版。 若要檢查您電腦中執行的 PowerShell 版本,請執行下列命令:

$PSVersionTable.PSVersion

如果您的版本已過時,請參閱升級現有的 Windows PowerShell

重要

本檔中所述的模組 AzureRM 會使用 .NET Framework。 這會使它與使用 .NET Core 的 PowerShell 6.0 不相容。 如果您使用PowerShell 6.0,請遵循 macOS和Linux的安裝指示。

安裝 Azure PowerShell 模組

您需要提升的許可權,才能從 PowerShell 資源庫 安裝模組。 若要安裝 Azure PowerShell,請在提升許可權的會話中執行下列命令:

Install-Module -Name AzureRM -AllowClobber

注意

如果您的 NuGet 版本早於 2.8.5.201,系統會提示您下載並安裝最新版的 NuGet。

根據預設,PowerShell 資源庫未設為 PowerShellGet 的信任存放庫。 第一次使用 PSGallery 時,您會看到下列提示:

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change
its InstallationPolicy value by running the Set-PSRepository cmdlet.

Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"):

回答 YesYes to All 繼續安裝。

AzureRM 模組是 Azure PowerShell Cmdlet 的彙總套件模組。 安裝會下載所有可用的 Azure Resource Manager 模組,並讓其 Cmdlet 可供使用。

登入

若要開始使用 Azure PowerShell,請使用您的 Azure 認證登入。

# Connect to Azure with an interactive dialog for sign-in
Connect-AzureRmAccount

注意

如果您已停用模組自動載入,則必須使用 Import-Module AzureRM手動匯入模組。 由於模組的結構方式,這可能需要幾秒鐘的時間。

您必須針對您啟動的每個新 PowerShell 工作階段重複這些步驟。 若要瞭解如何跨 PowerShell 工作階段保存 Azure 登入,請參閱 跨 PowerShell 會話保存使用者認證。

更新 Azure PowerShell 模組

您可以執行 Update-Module 來更新 Azure PowerShell 安裝。 此命令不會卸載舊版。

Update-Module -Name AzureRM

如果您想要從系統移除舊版的 Azure PowerShell,請參閱 卸載 Azure PowerShell 模組

使用多個版本的 Azure PowerShell

可以安裝一個以上的 Azure PowerShell 版本。 若要檢查您是否已安裝多個版本的 Azure PowerShell,請使用下列命令:

Get-InstalledModule -Name AzureRM -AllVersions |
  Select-Object -Property Name, Version

若要移除 Azure PowerShell 的版本,請參閱 卸載 Azure PowerShell 模組

如果您使用內部部署 Azure Stack 資源、執行舊版的 Windows,或使用 Azure 傳統部署模型,您可能需要一個以上的版本。 若要安裝舊版,請在安裝時提供 -RequiredVersion 自變數。

# Install version 2.3.0 of Azure PowerShell
Install-Module -Name AzureRM -RequiredVersion 2.3.0

載入 Azure PowerShell 模組時,預設會載入最新版本。 若要載入不同的版本,請指定 RequiredVersion 參數。

# Load version 2.3.0 of Azure PowerShell
Import-Module -Name AzureRM -RequiredVersion 2.3.0

提供意見反應

如果您在使用 Azure Powershell 時發現錯誤, 請在 GitHub 上提出問題。 若要從命令行提供意見反應,請使用 Send-Feedback Cmdlet。

後續步驟

若要開始使用 Azure PowerShell,請參閱 開始使用 Azure PowerShell ,以深入了解模組及其功能。