Friday, July 24, 2020

Automatically Updating NavContainerHelper

By Steve Endow

One of the challenges I've had using the Business Central NavContainerHelper module has been managing the versions and updates.  Freddy Kristiansen is constantly updating NavContainerHelper to add features or fix issues, so a new version might be released within 24 hours of the prior release.

It seems like there is at least one update per week.  As a result, I always forget to update NavContainerHelper and often end up using an older version, which can sometimes result in errors.

I wanted to automate the update process so that I always know that I have the latest version of NavContainerHelper installed.  And ONLY the latest version--making sure that I don't have any older versions installed side-by-side.

I don't know if this is the best method, but I think it should work.  If you know of a better way, let me know!

Here's the script I'd like to run automatically every day:

 $MyModuleName = 'NavContainerHelper'  
 Uninstall-Module $MyModuleName -Force -AllVersions  
 Install-Module $MyModuleName -Force  

The Script

I want to install the latest version, but I want to make sure that I don't have an older version still installed.  There are a few ways to do this, but I figure with this script, it removes all existing versions, and then installs the latest version.

I normally don't recommend Install-Module -Force if you are running the script manually, but in this case, I believe I need -Force in order to bypass the verification dialog that appears during installation.  Also, since I know that I've just uninstalled all versions before installing the latest version, I think using -Force should be okay in this particular case.

I saved the above 3 line script to a .ps1 file.

I then opened Windows Task Scheduler using Run As Administrator.

Windows Task Scheduler
I created a new folder called Steve to make it easier to find my tasks.

I then created a new task (not a Basic task).

Task - General Info

I gave the task a name.  Then I set the task to use the Local Administrator user.  This is on one of my dev VMs, and I know the PowerShell script will need Admin rights, so I chose Administrator just to avoid any hassles.  If you are on a company network / domain, you'll need to figure out which domain user / rights you need to allow the script to run as a task.

Nightly update
On the Triggers tab, I setup a schedule to run Daily at 8pm.

On the Actions tab, I created an action to call powershell with the -File argument, based on this blog post.



The argument I used looks like:

     -File C:\BCPowerShell\UpdateNavContainerHelper_v1.ps1


I then saved the task and tested it. 

It seems to work, so I'll keep an eye on it for a week or so to verify that NavContainerHelper is always on the latest version and that I don't have any old versions installed side-by-side.


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

http://www.precipioservices.com

No comments:

Post a Comment

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

How many digits can a Business Central Amount field actually support?

 by Steve Endow (If anyone has a technical explanation for the discrepancy between the Docs and the BC behavior, let me know!) On Sunday nig...