powershell - 如何强制 powershell 重新加载自定义模块?

标签 powershell powershell-5.0 powershell-module

我创建了一个模块“ActiveDirectory.psm1”,其中包含 powershellv5 中的一个类。我将该模块导入另一个名为“test.ps1”的文件中,然后从该类中调用一个方法。

test.ps1 包含以下内容:

using module '\\ser01\Shared\Scripts\Windows Powershell\modules\ActiveDirectory\ActiveDirectory.psm1'

Set-StrictMode -version Latest;

$AD = [ActiveDirectory]::New('CS');
$AD.SyncGroupMembership($True);

这一切都按预期工作,但是当我对 ActiveDirectory.psm1 进行更改并保存它们不会立即反射(reflect)的更改时。即如果 ActiveDirectory.psm1 包含:
write-verbose 'do something';

如果我将其更改为
write-verbose 'now the script does something else';

输出仍然是“做某事”

我猜它已经将模块存储在内存中并且没有重新加载它因此错过了我所做的更改。我需要运行什么命令来加载模块的最新保存版本?

最佳答案

正如 wOxxOm 所建议的那样,您可以尝试通过-Force旗帜:

Import-Module ... -Force
或者,如果这不起作用,请尝试显式删除它,然后使用以下命令重新导入:
Remove-Module

关于powershell - 如何强制 powershell 重新加载自定义模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39426477/

相关文章:

database - PowerShell 函数返回 DataSet/DataTable 的奇怪行为

powershell - 如何将变量传递给Start-Job?

powershell - 将主机写入列(格式化输出)

powershell - 如何从 powershell 模块函数导出变量?

powershell - 如何将powershell模块运送到生产环境?

Powershell 模块名称

powershell - 使用 WMI 获取 IIS6 网站的所有虚拟目录

powershell - 当脚本设置为 “Run As Admin”时,有没有办法在Powershell中映射本地驱动器?

windows - 未找到内置 DSC 资源

loops - 一个循环中有两个变量