Powershell Unload Module... completely

Viewed 44511

I'm working on debugging a Powershell project. I'm using Import-Module to load the PS module from my C# dll and everything works fine. Calling Remove-Module does not fully unload the module though as the DLL is still locked and can not be deleted.

Is there a way to get PSH to fully unload the module and release the DLL so that I can copy over it and reload it again using Import-Module without restarting the PSH console?

Update
So if you load a module into a seperate AppDomain does it still work like a normal module? Can anyone provide an example?

10 Answers

I've had the same issues and ended up wrapping the DLL I wanted to load inside a commandline exe which I then called from the script. In that way I avoided loading the DLL inside my application at all.

I had some external module (ImportExcel) I wanted to update like this and it did not work. For this situation Install-Module -Scope CurrentUser <MyExternalModuleName> (in case it is in your users module folder, otherwise omit the -Scope ... param) worked.

(How they managed it internally - I don't know, but you keep your current PS session.)

Related