With the introduction of PackageManagement and PowershellGet we got finally a modular environment in PowerShell than can easily be kept up to date.
For example if I’ve installed my MarkdownPS module with Install-Module -Name MarkdownPS
then I only need to execute Update-Module -Name MarkdownPS
to be on the latest version.
PowerShell comes with a couple of system modules. Actually everything is a module in terms of the PowerShell engine and even the PackageManagement, PowershellGet, Pester etc are modules.
But while writing some pester tests, I used some assertions described in Should that were not working.
Since I’m using and following Pester a lot, I knew the module was much ahead of my default environment so I need to update.
Naturally I ran Update-Module -Name Pester
although inside me I knew something would not work and i got this error:
Update-Module : Module ‘Pester’ was not installed by using Install-Module, so it cannot be updated.
At line:1 char:1
Update-Module -Name Pester
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (PowerShellGet:String) [Write-Error], WriteErrorException
FullyQualifiedErrorId : ModuleNotInstalledUsingInstallModuleCmdlet,Update-Module
The error message is good enough to understand what the problem is, so after some googling I landed into Update Manually Installed PowerShell Modules from the PowerShell Gallery.
Mike F Robbins has a very good solution, and I usually create cmdlets in my profile to enhance my PowerShell sessions.
When executing in my environment it looks like this.
PS C:\> Compare-SystemModuleWithGallery
Name InstalledVersion Repository Version
---- ---------------- ---------- -------
PSReadline 1.1 PSGallery 1.2
PowerShellGet 1.0.0.1 PSGallery 1.1.1.0
Pester 3.3.5 PSGallery 3.4.3
PackageMan... 1.0.0.1 PSGallery 1.1.0.0
To update Pester to the new version I executed Install-Module Pester -Scope CurrentUser -Force
.
After the manual install, you would expect that Compare-SystemModuleWithGallery
would not output an entry for Pester but the script checks all versions of system modules and therefore Pester will always show up.
You can validate this by querying what is available to your session using Get-Module
PS C:\> Get-Module Pester -ListAvailable
Directory: C:\Users\asarafian\Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 3.4.3 Pester {Describe, Context, It, Should...}
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 3.3.5 Pester {Describe, Context, It, Should...}
You can also verify that you are using the highest version with these steps
- Import the module or use one of its cmdlets.
- Get the loaded module and show the version
PS C:\> Import-Module Pester
PS C:\> Get-Module Pester|Format-Table Name,Version
Name Version
---- -------
Pester 3.4.3
From the result you notice that I’m indeed using the latest version 3.4.3
.
From this points, updating the module is as easy as Update-Module Pester
.
As far as I know, the PowerShell team had plans to roll out updates for these modules and any other system module, but at the time of the PowerShell v5.0 release, they had not the time to finish it properly. But its PowerShell and we can always improve with some tricks added to our profile.
Leave a Comment