Azure PowerShell 的離線安裝
在某些環境中,無法連線到因特網或 PowerShell 資源庫。 在這些情況下,您可以使用下列其中一種方法脫機安裝 Az PowerShell 模組。
注意
本文中脫機安裝的選項至少需要一個具有因特網存取權的系統,才能下載 Az PowerShell 模組,這與您打算安裝模組的系統不同。
先決條件
跨平臺
Az PowerShell 模組的下列安裝選項可在所有平臺上跨平臺使用,包括 Windows、Linux 和 macOS。
從 tar 檔案安裝
提示
tar
命令行公用程式必須使用這個安裝選項。 其預設可在 Windows 10 版本 1803 或更高版本、大部分 Linux 發行版和目前版本的 macOS 上使用。
在可存取因特網的系統上,定義您要儲存 tar 封存的目的地路徑。
$downloadFolderPath = "$home/Downloads"
確認下載資料夾存在。 否則,請建立資料夾。
if (-not (Test-Path -Path $downloadFolderPath -PathType Container)) { New-Item -Path $downloadFolderPath -ItemType Directory }
判斷 GitHub 上最新 Az PowerShell 模組版本的 tar 封存 URL。
$tarSourceUrl = ( Invoke-RestMethod -Uri https://api.github.com/repos/azure/azure-powershell/releases/latest | Select-Object -ExpandProperty assets | Where-Object content_type -eq 'application/x-gzip' ).browser_download_url
將 tar 檔名和目的地檔案路徑儲存在變數中。
$fileName = Split-Path -Path $tarSourceUrl -Leaf $downloadFilePath = Join-Path -Path $downloadFolderPath -ChildPath $fileName
使用 PowerShell 從 GitHub 下載 tar 封存盤。
Invoke-WebRequest -Uri $tarSourceUrl -OutFile $downloadFilePath
如果您執行 Windows作系統,請解除封鎖下載的檔案。
if ($PSVersionTable.PSVersion.Major -le 5 -or $IsWindows -eq $true) { Unblock-File -Path $downloadFilePath }
注意
將 tar 封存複製到離線系統。 定義
$downloadFilePath
和$downloadFolderPath
變數,或指定實際值,而不是在離線系統上使用下列命令中的變數。擷取 tar 封存的內容。
tar zxf $downloadFilePath -C $downloadFolderPath
在您要安裝 Az PowerShell 模組的離線系統上執行
InstallModule.ps1
腳本,這是其中一個解壓縮的檔案。.$downloadFolderPath/InstallModule.ps1
儲存和複製安裝
使用可存取因特網和 PowerShell 資源庫的系統,將具有 Save-Module
或 Save-PSResource
的 Az PowerShell 模組下載到網路位置。 這些命令會將 Az 模組及其相依性儲存至指定的位置。 使用儲存的模組作為安裝來源,並將其複製到離線系統。
從私人存放庫安裝
在您的局域網路上建立私人存放庫,並將其作為離線系統的安裝來源。 若要了解更多,請參閱 使用私用 PowerShellGet 存放庫。
此方法可讓您在單一伺服器或檔案共用上快取 PowerShell 模組,以使用 PowerShellGet 或 Microsoft.PowerShell.PSResourceGet 部署到任何中斷聯機的系統。
窗戶
在 Windows 上,如果您使用 Windows PowerShell 5.1 版,您也可以選擇使用 MSI 安裝 Az PowerShell 模組。
重要
請記住,MSI 安裝程式僅適用於 Windows PowerShell 5.1。
故障排除
如需 Az PowerShell 模組常見安裝問題的解決方案,請參閱 針對 Az PowerShell 模組的安裝問題進行疑難排解。
另請參閱
後續步驟
若要深入瞭解如何使用 Az PowerShell 模組管理 Azure 資源,請參閱 開始使用 Azure PowerShell。