即使位于路径中并且脚本手动成功执行,我的PowerShell模块也不会在某些环境中加载。即使位于路径中,导入模块仍未找到
eg.My PowerShell脚本包含以下内容:
Write-Host $env:PSModulePath
Import-Module SSH-Sessions
的SSH的会话模块已摆在PSModulePath中C:\Windows\system32\WindowsPowerShell\v1.0\Modules\SSH-Sessions
。它使用命令powershell .\folder\test.ps1
执行。
脚本的第一行的输出显示模块路径是:C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
当在命令执行提示所有作品如预期,但作为一个颠覆post-commit钩子或作为詹金斯建立步骤中,该失败以下错误:
Import-Module : The specified module 'SSH-Sessions' was not loaded because no
valid module file was found in any module directory.
At C:\path\to\workspace\folder\test.ps1
:2 char:14
+ Import-Module <<<< SSH-Sessions
+ CategoryInfo : ResourceUnavailable: (SSH-Sessions:String) [Impo
rt-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
ands.ImportModuleCommand
为什么PowerShell的找不到模块?
首先,您没有对该目录的写入权限。难道无法加载模块的PowerShell实例是由另一个用户运行的,并且'SSH-Sessions'文件夹仅存在于当前用户的'$ Env:LocalAppData \ VirtualStore'中? – Joey
当脚本在subversion挂钩中运行时,它是否会给出'Write-Host $ env:PSModulePath'的任何输出?一个颠覆挂钩开始于一个空的环境,甚至不设置'%PATH%'。 –
请注意,在64位操作系统中,有两个这样的目录c:\ windows \ system32 \ windowsPowershell \ v1.0 \ modules和c:\ windows \ syswow64 \ windowsPowershell \ v1.0 \ modules。使用的取决于托管应用程序的位数 - 通常取决于托管应用程序如何调用PowerShell。 –