我接受了trebleCode's answer,但我想提供更多详细信息,说明我按照 trebleCode 的回答,在未连接的 Win 7 机器上安装感兴趣的 nupkg pswindowsupdate.2.0.0.4.nupkg 的步骤。
首先:经过一番挖掘,我想我找到了 trebleCode 所指的 MS 文档:
Bootstrap the NuGet provider and NuGet.exe
Install-PackageProvider
要继续,如 trebleCode 所述,我做了以下操作
在我连接的机器上安装 NuGet 提供程序
在连接的机器(Win 10 机器)上,我从 PS 命令行运行 Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.208 -Force。 Nuget 软件是从 'Net 获得并安装在我本地连接的机器上。
安装后,我在C:\Program Files\PackageManagement\ProviderAssemblies 找到了 NuGet 提供程序软件(注意:文件夹名称 \ProviderAssemblies 而不是 \ReferenceAssemblies 是相对于 trebleCode 答案的一个小区别。
提供者软件的文件夹结构如下:
C:\Program Files\PackageManagement\ProviderAssemblies
\NuGet
\2.8.5.208
\Microsoft.PackageManagement.NuGetProvider.dll
在我未连接的机器上安装 NuGet 提供程序
我将 \NuGet 文件夹(及其所有子文件夹)从连接的机器复制到拇指驱动器上,并将其复制到我未连接的 (Win 7) 机器上的 C:\Program Files\PackageManagement\ProviderAssemblies
我在未连接 (Win 7) 的机器上启动 PS (v5) 并运行 Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.208 以将提供程序导入当前的 PowerShell 会话。
我跑了Get-PackageProvider -ListAvailable 并看到了这个(NuGet 出现在以前不存在的地方):
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, PublishLocati...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
在我未连接的机器上创建本地存储库
在未连接的 (Win 7) 机器上,我创建了一个文件夹作为我的 PS 存储库(例如,c:\users\foo\Documents\PSRepository)
我注册了 repo:Register-PSRepository -Name fooPsRepository -SourceLocation c:\users\foo\Documents\PSRepository -InstallationPolicy Trusted
安装 NuGet 包
我在未连接的 Win7 机器上获取并复制了 nupkg pswindowsupdate.2.0.0.4.nupkg 到 c:\users\foo\Documents\PSRepository
我通过执行Find-Module -Repository fooPsRepository获知了模块的名称
Version Name Repository Description
------- ---- ---------- -----------
2.0.0.4 PSWindowsUpdate fooPsRepository This module contain functions to manage Windows Update Client.
我通过执行Install-Module -Name pswindowsupdate安装了模块
我通过执行 Get-Command –module PSWindowsUpdate验证了安装的模块
CommandType Name Version Source
----------- ---- ------- ------
Alias Download-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Get-WUInstall 2.0.0.4 PSWindowsUpdate
Alias Get-WUList 2.0.0.4 PSWindowsUpdate
Alias Hide-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Install-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Show-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias UnHide-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Uninstall-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Cmdlet Add-WUServiceManager 2.0.0.4 PSWindowsUpdate
Cmdlet Enable-WURemoting 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUApiVersion 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUHistory 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUInstallerStatus 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUJob 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WULastResults 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WURebootStatus 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUServiceManager 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUSettings 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUTest 2.0.0.4 PSWindowsUpdate
Cmdlet Invoke-WUJob 2.0.0.4 PSWindowsUpdate
Cmdlet Remove-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Cmdlet Remove-WUServiceManager 2.0.0.4 PSWindowsUpdate
Cmdlet Set-WUSettings 2.0.0.4 PSWindowsUpdate
Cmdlet Update-WUModule 2.0.0.4 PSWindowsUpdate
我觉得我可以走了