Module Imported or Maybe Not…

Jake Moening
Mar 1, 2016 · 2 min read

For some reason Microsoft decided when it came to PowerShell to make a nice little gotcha for every new PS developer. When you finally get around to making your first PS module you are likely to perform this little dance more than a few times:

## Edit your .psm1 module…C:\> Import-Module ./mymodule.psm1C:\> Start-MyThingERROR YOU MADE A DUMB TYPO!## Edit your .psm1 module again to fix the small issue…C:\> Import-Module ./mymodule.psm1C:\> Start-MyThingERROR YOU MADE A DUMB TYPO!

Wait… Didn’t we just fix that? Can you spot the issue above?

If you said that it failed to import the module the second time you have obviously been burned by this a few times already. That or you have a super power that allow you to see the hidden error/warning that Microsoft surely output to let us know that it didn’t actually do what we asked (re-import the module with the new changes).

Since 99.999% of us don’t have super powers here’s the deal: Once you import a module with PowerShell, any further attempt to do so without removing the module first will silently not load the updated module and simply leave the old one in place resulting in one of those maddening debug sessions where only after an hour of banging you’re head against the wall you figure out you are still running old code…

I’m sure there was a perfectly reasonable explanation for why it was designed like this, but I’m too lazy to look it up right now so I’m just going to leave this warning for all the newbies out there. When working on a Powershell module ALWAYS remember to Remove-Module prior to Import-Module or you will be in for some frustration.

Shameless Self-Promotion

If that seems like a silly thing to have to remember then be sure to checkout my UnsignedBytes Build Tools project that takes care of remembering stuff like this for you :)

Jake Moening

Written by

Married, software-developing, backpacking, photographing, cooking, father of three. https://www.codecutting.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade