如何安裝PowerShellGet和 PSResourceGet

必要條件

請確定您已安裝 1.0.0.1 之前的 PowerShellGetPackageManagement 版本。 最新的穩定版本是 PowerShellGet 的 2.2.5, 而 PackageManagement 則為 1.4.8.1。

如果您使用PowerShellGet 1.0.0.1執行 Windows PowerShell 5.1,請參閱更新 Windows PowerShell 5.1 的 PowerShellGet

若要存取 PowerShell 資源庫,您必須使用傳輸層安全性 (TLS) 1.2 或更高版本。 使用下列命令在 PowerShell 工作階段中啟用 TLS 1.2。

[Net.ServicePointManager]::SecurityProtocol =
    [Net.ServicePointManager]::SecurityProtocol -bor
    [Net.SecurityProtocolType]::Tls12

將此命令新增至您的 PowerShell 配置檔腳本,以確保已針對每個 PowerShell 會話設定 TLS 1.2。 如需設定檔的詳細資訊,請參閱 about_Profiles

如果您正在執行 PowerShell 6.0 或更新版本,則已安裝較新版本的 PowerShellGetPackageManagement 。 如有必要,您可以升級至較新版本,或安裝預覽版本。 您應該一律安裝最新的穩定版本。

使用下列命令來查看已安裝的版本。

Get-Module PowerShellGet, PackageManagement -ListAvailable

下列輸出顯示必須安裝最新的穩定版本。

    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version  Name               ExportedCommands
---------- -------  ----               ----------------
Binary     1.0.0.1  PackageManagement  {Find-Package, Get-Package, ...
Script     1.0.0.1  PowerShellGet      {Install-Module, Find-Module, ...

安裝最新的穩定版本

若要安裝這些模組的最新版本,請執行下列命令:

Install-Module PowerShellGet -Force -AllowClobber

安裝 Microsoft.PowerShell.PSResourceGet

Microsoft.PowerShell.PSResourceGet 是 PowerShell 的新套件管理解決方案。 在此課程模組中,您不再需要使用 PowerShellGetPackageManagement。 不過,它可以與現有的 PowerShellGet 模組並存安裝。 若要與現有的 PowerShellGet 版本並存安裝 Microsoft.PowerShell.PSResourceGet,請開啟任何 PowerShell 控制台並執行:

Install-Module Microsoft.PowerShell.PSResourceGet -Repository PSGallery

Microsoft.PowerShell.PSResourceGet 已預安裝 PowerShell 7.4 和更新版本。