首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >指定的模块未加载“PSWindowsUpdate”

指定的模块未加载“PSWindowsUpdate”
EN

Stack Overflow用户
提问于 2015-01-27 06:06:04
回答 1查看 4.7K关注 0票数 3

描述:我正在运行/执行来自ruby脚本(.rb)文件的powershell

代码语言:javascript
运行
复制
exec "powershell.exe Import-Module PSWindowsUpdate"

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

代码语言:javascript
运行
复制
%WINDIR%\System32\WindowsPowerShell\v1.0\Modules

当我运行上面的代码时,我会得到以下错误:

代码语言:javascript
运行
复制
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 $:'"的结果是:

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-27 11:23:26

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

\vmware-主机\共享Folders\Documents\WindowsPowerShell\Modules;C:\Program文件(x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\M模块\

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

然后我得到了:

导入模块:未加载指定模块“PSWindowsUpdate”,因为在任何模块directory.At行中都没有找到有效的模块文件:1 char:39

接着,我跑了:

代码语言:javascript
运行
复制
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"):

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28164218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档