How do I force powershell to reload a custom module?

只谈情不闲聊 提交于 2020-01-01 22:47:50

问题


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 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);

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';

If I change that to

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

the output remains 'do something'

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?


回答1:


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

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.




回答2:


Import-Module 'E:\xxx.ps1' -Force




回答3:


For anyone else coming across this issue, see https://github.com/PowerShell/PowerShell/issues/2505

It seems that there is a known long-standing bug regarding importing of modules that are anything above rudimentary level in complexity (for example, I have a module with a single class and class method that fails to update).



来源:https://stackoverflow.com/questions/39426477/how-do-i-force-powershell-to-reload-a-custom-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!