How do I force powershell to reload a custom module?

S. Mitchell picture S. Mitchell · Sep 10, 2016 · Viewed 38.4k times · Source

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?

Answer

DAXaholic picture DAXaholic · Sep 11, 2016

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.