如何安装特定版本的 PowerShell 模块?
powershellmicrosoft technologiessoftware & coding
要安装特定版本的 PowerShell 模块,我们需要在 Install-Module 命令中使用 -RequiredVersion 参数。
要查找可用的模块版本,我们可以使用 Find-Module 命令,并配合 -AllVersions 参数,该参数会检索 PSGallery 中所有可用的模块版本。
在本示例中,我们将使用 7Zip4PowerShell 模块。
示例
Find-Module 7zip4PowerShell -AllVersions | ft -AutoSize
运行此命令后,您可以看到此模块有多个版本可用。
输出
Version Name Repository ------- ---- ---------- 1.13.0 7Zip4Powershell PSGallery 1.12.0 7Zip4Powershell PSGallery 1.11.0 7Zip4Powershell PSGallery 1.10.0.0 7Zip4Powershell PSGallery 1.9.0 7Zip4Powershell PSGallery 1.8.0 7Zip4Powershell PSGallery 1.7.1 7Zip4Powershell PSGallery
我们需要为所有用户安装 1.9.0 版本,因此我们将使用以下命令。
示例
Install-Module 7Zip4PowerShell -RequiredVersion 1.8.0 -Scope AllUsers -Force -Verbose
要在远程服务器上安装 PowerShell 模块,请使用以下命令。
语法
Invoke-Command -ComputerName RemoteMachine1 -ScriptBlock {Install-Module 7Zip4PowerShell -RequiredVersion 1.8.0 -Scope AllUsers -Force -Verbose}

