如何强制 powershell 重新加载自定义模块? [英] How do I force powershell to reload a custom module?

查看:28
本文介绍了如何强制 powershell 重新加载自定义模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a module 'ActiveDirectory.psm1' which contains a class in powershellv5. I am importing that module in another file called 'test.ps1' and then calling a method from the class.

test.ps1 包含以下内容:

test.ps1 contains the following:

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

Set-StrictMode -version Latest;

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

当我对 ActiveDirectory.psm1 & 进行更改时,一切都按预期工作保存它们不会立即反映的更改.即如果 ActiveDirectory.psm1 包含:

It all works as expected BUT when I make a change to ActiveDirectory.psm1 & save the changes they aren't reflected immediately. i.e. if ActiveDirectory.psm1 contains:

write-verbose 'do something';

如果我把它改成

write-verbose 'now the script does something else';

输出仍然是做某事"

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

I'm guessing it has stored the module in memory and doesn't reload it therefore missing the changes I have made. What command do I need to run to load the most recent saved version of the module?

推荐答案

wOxxOm 所建议的,请尝试 Import-Module ... -Force 或者如果这不起作用尝试使用 Remove-Module 显式删除它并重新导入它

As suggested by wOxxOm try Import-Module ... -Force or if that does not work try to explicitly remove it with Remove-Module and reimport it

我刚刚创建了答案,以便在解决后可以关闭问题 - 如果 wOxxOm 将创建一个回答我会删除这个.

I just created the answer so that the question can be closed if solved - if wOxxOm will create an answer I will delete this one.

这篇关于如何强制 powershell 重新加载自定义模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆