未加载指定的模块 'PSWindowsUpdate'

The specified module was not loaded 'PSWindowsUpdate'

描述:我是来自 ruby 脚本 (.rb) 文件的 running/executing 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 执行此操作时,它 运行 非常好。

我正在使用:

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

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

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

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

然后我得到:

Import-Module : The specified module 'PSWindowsUpdate' was not loaded because no valid module file was found in any module directory.At 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"):

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