2
我試圖安裝一個PS模塊,以便它可以從任何地方導入。我已經將我的安裝目錄添加到環境變量中,並且沒有工作,所以我嘗試將我的模塊放入PSCX目錄,因爲我知道這個目錄有效。以下是顯示問題的命令行歷史記錄。爲什麼「import-module foo」不能在這裏工作?爲什麼我無法讓我的模塊從PSModulePath中的目錄加載?
C:\Program Files (x86)\PowerShell Community Extensions\pscx3\Pscx> $env:PSModulePath
C:\Users\chris\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\;C:\windows\system32\WindowsPowerShell\v1.0\Modules\
# There's my module; foo.psm1
C:\Program Files (x86)\PowerShell Community Extensions\pscx3\Pscx> dir *.psm1
Directory: C:\Program Files (x86)\PowerShell Community Extensions\pscx3\Pscx
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 3/28/2013 10:37 AM 44 foo.psm1
-a--- 10/20/2012 8:52 PM 19658 Pscx.psm1
# this works, as expected, so my PSModulePath seems correct.
C:\Program Files (x86)\PowerShell Community Extensions\pscx3\Pscx> import-module -force pscx
# I expect this to work since the module is in a PSModulePath directory... but it doesn't
C:\Program Files (x86)\PowerShell Community Extensions\pscx3\Pscx> import-module foo
import-module : The specified module 'foo' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ import-module foo
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (foo:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
# Try again with the extension... nope.
C:\Program Files (x86)\PowerShell Community Extensions\pscx3\Pscx> import-module foo.psm1
import-module : The specified module 'foo.psm1' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ import-module foo.psm1
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (foo.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
# I can import the module if I give the path
C:\Program Files (x86)\PowerShell Community Extensions\pscx3\Pscx> import-module ./foo.psm1 -verbose:$true
VERBOSE: Importing function 'fooobar'.
看來愚蠢的,你需要一個'foo'文件夾中包含了'foo.p *'文件,但它的工作原理。 – Lucas