Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 指定的模块未加载';PSWindowsUpdate';_Ruby_Powershell_Import Module - Fatal编程技术网

Ruby 指定的模块未加载';PSWindowsUpdate';

Ruby 指定的模块未加载';PSWindowsUpdate';,ruby,powershell,import-module,Ruby,Powershell,Import Module,说明:我正在从ruby脚本(.rb)文件运行/执行powershell 我从“”下载了PSWindowsUpdate模块,并将文件复制到以下位置: %WINDIR%\System32\WindowsPowerShell\v1.0\Modules 当我运行上述命令时,会出现以下错误: Z:\Desktop>ruby windows_patch.rb Import-Module : The specified module 'PSWindowsUpdate' was not loaded b

说明:我正在从ruby脚本(.rb)文件运行/执行powershell

我从“”下载了
PSWindowsUpdate
模块,并将文件复制到以下位置:

%WINDIR%\System32\WindowsPowerShell\v1.0\Modules
当我运行上述命令时,会出现以下错误:

Z:\Desktop>ruby windows_patch.rb
Import-Module : The specified module 'PSWindowsUpdate' was not loaded because
no valid module file was found in any module directory.At line:1 char:1
+ Import-Module PSWindowsUpdate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PSWindowsUpdate:String) [I
   mport-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
   ands.ImportModuleCommand
然而,当我通过Powershell运行此程序时,它运行得非常好

我正在使用:

  • Windows 7 x64
  • PowerShell v4
  • Ruby v2.1.5
exec“powershell.exe ruby-e”put$:”
的结果是:

C:/Ruby21/lib/ruby/site_ruby/2.1.0
C:/Ruby21/lib/ruby/site_ruby/2.1.0/i386-msvcrt
C:/Ruby21/lib/ruby/site_ruby
C:/Ruby21/lib/ruby/vendor_ruby/2.1.0
C:/Ruby21/lib/ruby/vendor_ruby/2.1.0/i386-msvcrt
C:/Ruby21/lib/ruby/vendor_ruby
C:/Ruby21/lib/ruby/2.1.0
C:/Ruby21/lib/ruby/2.1.0/i386-mingw32

我运行了
powershell.exe$env:PSModulePath
,它给了我:

\vmware主机\Shared Folders\Documents\WindowsPowerShell\Modules;C:\ProgramFiles(x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\M 奥杜勒斯\

然后我将文件夹复制到
C:\ProgramFiles(x86)\WindowsPowerShell\Modules

然后我得到:

导入模块:指定的模块“PSWindowsUpdate”未加载,因为 在任何模块目录中都找不到有效的模块文件。第1行字符:39

接下来,我接着跑:

PS C:\Users\Justin.Schuhmann> Set-ExecutionPolicy -Scope LocalMachine

cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: Unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

这解决了问题,我还没有一个永久的解决方案,因为这只是暂时的。设置

时,尝试执行exec“powershell.exe ruby-e”put$:“这将打印可供dry
powershell访问的模块目录
@mudasobwa添加了上述结果,以便将模块解包到任何已知位置(例如到
C:/Ruby21/lib/ruby/vendor\u ruby
)而不是
%WINDIR%\System32\WindowsPowerShell\v1.0\Modules
。Ruby模块不是PS模块,反之亦然。@mudasobw复制到该位置和
C:/Ruby21/lib/Ruby/vendor\u Ruby/2.1.0
噢,对不起,这是我弄错的。我仔细阅读了模块说明,意识到
PSWindowsUpdate
是PS模块,而不是ruby模块。所以问题是PS找不到它。请忽略我的错误建议,将其解压缩到ruby模块目录中。
PS C:\Users\Justin.Schuhmann> Set-ExecutionPolicy -Scope LocalMachine

cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: Unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):