Wednesday, July 8, 2020

I'm no PowerShell expert: Discovering Update-Module for NavContainerHelper

By Steve Endow

I wrote a post in April, "Make sure to update NavContainerHelper", in which I described some issues I had that were caused by having several old versions of the NavContainerHelper module installed.

Today, while updating the NavContainerHelper module on my Docker VM, I learned a few things, and I think I finally have a basic understanding of the PowerShell Module install and update process.

If you're a PowerShell pro or a NavContainerHelper pro, this will probably seem obvious, but as a newbie with both tools, it was a "learning moment" for me that explained the issues I had previously with multiple NavContainerHelper versions.

Let's start with a screen shot.

Install-Module -Force Warning

This morning I wanted to carefully update NavContainerHelper.  I wanted to make sure that I was not installing multiple versions, and I also wanted to verify I was getting the correct version, as Freddy had just tweeted a note about version

Let's update!

Also, I had recently learned about "Update-Module" from Daniel, although he indicated that he had issues with it.

Update-Module, you say?

This morning I wanted to carefully test the update process and see which commands would work best.

I first used Get-InstalledModule navcontainerhelper to verify my current version.

Then I tried Install-Module navcontainerhelper.  At the time, I didn't realize that I hadn't included the "-Force" parameter.  This turned out to be a fortuitous accident.

This was the message that I received:

WARNING: Version '' of module 'navcontainerhelper' is already installed at 'C:\Program Files\ WindowsPowerShell\ Modules\ navcontainerhelper\'. To install version '', run 
Install-Module and add the -Force parameter, this command will install version '' in side-by-side with version ''.

Why hadn't I seen this warning before?  This message makes complete sense!  "Hey dude, are you SURE you really want to do this?".

This is why I'd never seen the warning before:

The perils of copying someone else's code

This is a generic NavContainerHelper script that I had downloaded long ago and have been using for probably 2 years.  It used the "-force" parameter, and I never thought to look into what that parameter did.

In Daniel's tweet, he also included it in "Install-Module $MyModuleName -Force"

So why is everyone automatically including -Force with Install-Module?  It suppresses version warnings.  It can result in side-by-side version installs of the same module, which can cause all sorts of bizarre behavior, as I documented in my April post.  So, why use it by default with NavContainerHelper?

Here is the documentation for the Install-Module -Force parameter for PowerShell 5.1.

Do you really need to force it?

Based on my experience so far, I don't want to suppress or override warning messages about installation conflicts with NavContainerHelper.  I don't want multiple versions of NavContainerHelper to be installed.

I want to see the warnings and errors and know if I'm doing something wrong / dumb / that I'll regret later.

So why use -Force at all?  I don't know yet. Maybe there's some valid reason why you might need to use -Force when installing or updating NavContainerHelper that I just haven't encountered yet.

But if I don't use -Force, I get a warning that prevents a new version of NavContainerHelper from being installed.  So how do I then update the module without -Force?

Based on the suggestion from Daniel, it seems like there are two alternatives.

1. Use Uninstall-Module, then Install-Module (but I'd omit -Force)
2. Use Update-Module

Given Daniel's warning about Update-Module not working, I wanted to test it to see what it would do, or wouldn't do.

Did it work? Looks like it worked?

Um.  Well.  It seems like Update-Module worked.  No errors.  The new version is listed.  The old version is not listed.  Success?

So...  If that works, I think it makes sense for me to use Update-Module NavContainerHelper.

UPDATE:  After additional conversation with Daniel on Twitter, he pointed out that Update-Module NavContainerHelper will result in a confirmation dialog.  If you want to suppress that dialog, you can use Update-Module NavContainerHelper -Force, which apparently only suppresses the confirmation.  It should not do anything zany like install multiple versions side-by-side.

But I'm left with two questions:

1.  Why would I ever want to use Install-Module NavContainerHelper -Force ?  Is there some situation where a new install won't complete unless -Force is included?

2.  If I already have NavContainerHelper installed, why wouldn't I want to use Update-Module?  Is there some bug or quirk that makes it unreliable?

UPDATE:  Erik shared that he uses Update-Module and it works fine for him. That sounds like a pretty good endorsement, so I'm going to use Update-Module and keep an eye on it to make sure it  works properly.

Good enough for me!

If anyone has thoughts on either of these, I'd love to hear them!

Steve Endow is a Microsoft MVP in Los Angeles.  He works with Dynamics 365 Business Central, Microsoft Power Automate, Power Apps, Azure, .NET, Dynamics GP, and SQL Server.

You can also find him on Twitter and YouTube

No comments:

Post a Comment

All comments must be reviewed and approved before being published. Your comment will not appear immediately.

Page Inspection Keyboard Shortcut CTRL+ALT+F1 Doesn't Work on Laptop

By Steve Endow Update: I originally wrote this post referencing my Lenovo ThinkPad P1 laptop, but it appears that similar Intel Graphics sof...