Powershell模块无法被发现

时间:2014-12-17 14:58:08

标签: powershell module

对此有一段时间! Powershell v4无法找到MyModule模块,我已经在所有的$ env:PSModulePath位置尝试了它,包括添加我的,我在get-module上尝试了-refresh参数......没什么,有什么想法吗?

PS Scripts:\> gci C:\Users\lgriffith\Documents\WindowsPowerShell\Modules\MyModule


    Directory: C:\Users\lgriffith\Documents\WindowsPowerShell\Modules\MyModule


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        17/12/2014     13:36       1601 Luke-Module.psm1


PS Scripts:\> Get-Module -ListAvailable


    Directory: C:\Users\lgriffith\Documents\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4        ShowUI                              {Get-ApplicationCommand, Get-Component...


    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.0.0.0    AppLocker                           {Set-AppLockerPolicy, Get-AppLockerPol...
Manifest   1.0.0.0    BitsTransfer                        {Add-BitsFile, Remove-BitsTransfer, Co...
Manifest   1.0.0.0    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimCla...
Script     1.0.0.0    ISE                                 {New-IseSnippet, Import-IseSnippet, Ge...
Manifest   3.0.0.0    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Cou...
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Ite...
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate,...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Ta...
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCre...
Binary     1.0        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Sta...
Script     1.0.0.0    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombi...
Binary     1.1.0.0    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remov...
Manifest   2.0.0.0    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PS...
Manifest   1.0.0.0    PSWorkflowUtility                   Invoke-AsWorkflow
Manifest   1.0.0.0    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-Troub...


PS Scripts:\> ipmo MyModule
ipmo : The specified module 'MyModule' was not loaded because no valid module file was found in
any module directory.
At line:1 char:1
+ ipmo MyModule
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (MyModule:String) [Import-Module], FileNotFound
   Exception
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCom
   mand

1 个答案:

答案 0 :(得分:1)

模块文件的名称必须与其存储的目录名称相匹配。

例如,

C:\Users\lgriffith\Documents\WindowsPowerShell\Modules\MyModule\Luke-Module.psm1

无效,而

C:\Users\lgriffith\Documents\WindowsPowerShell\Modules\MyModule\MyModule.psm1

应该有用。