Powershell 编辑已导入的模块

Powershell 编辑已导入的模块,powershell,module,import-module,Powershell,Module,Import Module,在导入我的powershell模块(MyModule.psm1)之前,我在其中编写了一个函数: Function T1() { Write-Host "T1 is just called" -ForegroundColor red } 在myMyModule.psd1中: @{ PowerShellVersion = '2.0' PowerShellHostName = '' PowerShellHostVersion = '2.0' RequiredM

在导入我的powershell模块
(MyModule.psm1)
之前,我在其中编写了一个函数:

Function T1()
{
    Write-Host "T1 is just called" -ForegroundColor red
}
在my
MyModule.psd1中:

@{
    PowerShellVersion = '2.0'
    PowerShellHostName = ''
    PowerShellHostVersion = '2.0'
    RequiredModules = @()
    ScriptsToProcess = @()
    NestedModules = @()
    FunctionsToExport = '*'
    CmdletsToExport = '*'
    VariablesToExport = '*'
    ModuleList = @()
    FileList = @()
}
当我将两个文件复制到以下位置时,这可以很好地导入:

C:\Users\fwaheed\Documents\WindowsPowerShell\Modules\MyModule

我能够在PowerShell会话中运行
T1
。但现在我想在同一模块中添加一个新功能,即:

Function T2()
{
    Write-Host "Its now T2.." -ForegroundColor red
}

即使重新启动PowerShell会话,它也无法识别
T2
,但是
T1
仍在工作。如何编辑已导入的模块,使更改立即可用。

导入模块后,将无法识别对其所做的更改,因为该模块已加载到内存中。但是,我始终能够执行
删除模块foo
,然后执行
导入模块foo
以加载新函数


尽管如此,您的PSD1文件看起来不正确。它应该有一个
ModuleToProcess
字段设置为“MyModule.psm1”。然后,当您执行导入模块MyModule
或导入模块。\MyModule.psd1时,PowerShell将查找并加载相关的
MyModule.psm1
文件。我想知道这是否会导致您与PowerShell的某些缓存发生冲突?

-Force
命令与
导入模块一起使用,它将重新加载它。

下面是迄今为止唯一对我有效的解决方案,在该解决方案中,我没有找到任何其他解决方案来工作和调试PowerShell类


导入模块mymodule-force
还不够?也尝试过,但没有成功(感谢老兄…刚刚删除了模块,再次导入,并尝试使用“导入模块MyModule-force”它通过添加4个函数来工作…Keith,我只发布了psd1文件的一部分,该文件正在设置导出方法。它有ModuleToProcess,或者它将无法导入我的模块脚本,对吗?这有点正确。导入psd1时,您必须有该条目才能加载PSM1。但是,您可以导入模块mymodule.psm1绕过您的PSD1。我很确定,如果您导入模块mymodule,它将处理PSD1,然后它将指示PowerShell需要加载mymodule.psm1。