【问题标题】:The specified module was not loaded 'PSWindowsUpdate'指定的模块未加载“PSWindowsUpdate”
【发布时间】:2015-01-27 06:06:04
【问题描述】:

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

exec "powershell.exe Import-Module PSWindowsUpdate"

我从“Windows Update PowerShell Module”下载了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 'puts $:'" 的结果是:

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

【问题讨论】:

  • 尝试使用exec "powershell.exe ruby -e 'puts $:'",它将打印模块目录可用于干powershell
  • @mudasobwa 添加了上面的结果
  • 所以解压模块到任何已知位置(例如C:/Ruby21/lib/ruby/vendor_ruby)而不是%WINDIR%\System32\WindowsPowerShell\v1.0\Modules。 Ruby 模块不是 PS 模块,反之亦然。
  • @mudasobwa 完全相同的错误复制到该位置和C:/Ruby21/lib/ruby/vendor_ruby/2.1.0
  • 哦,对不起,那是我搞混了。我仔细阅读了模块说明,发现PSWindowsUpdatePS 模块,而不是ruby 模块。所以问题是PS找不到。请忽略我的错误建议,将其提取到 ruby​​ 模块目录中。

标签: ruby powershell import-module


【解决方案1】:

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

\vmware-host\Shared Folders\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\M 模块\

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

然后我得到了:

Import-Module : 未加载指定的模块“PSWindowsUpdate”,因为 在任何模块目录中都找不到有效的模块文件。在 line:1 char: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"):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 1970-01-01
    相关资源
    最近更新 更多