我试图通过将ps1脚本从Linux机器推送到Windows机器,然后尝试通过ssh执行脚本,自动从Windows机器上的自定义存储库安装模块。 Windows正在运行一个cygwin服务器。当我直接在powershell上运行ps1脚本时,脚本运行正常。但是当我在ssh上运行相同时,它会因以下错误而失败:
PackageManagement\Install-Package : Exception calling "CloneRequest" with "3" argument(s): "Object reference not set
to an instance of an object."
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1875 char:34
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exce
ption
+ FullyQualifiedErrorId : NullReferenceException,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
脚本在以下行失败:
Find-Module -Name <module name> -AllVersions -Repository <repo name> | Install-Module -SkipPublisherCheck -Scope AllUsers -Force
这就是我从linux机器调用脚本的方式:
ssh user@windowsIp powershell -NonInteractive -File E:\moduleInstaller.ps1 repositoryUrl moduleName moduleVersion