It’s important to check every now and then that your PowerShell modules are up-to-date. If you are using old and outdated modules, you can run into issues, just like using old and outdated software in general.

For example, the PowerShellGet module provides cmdlets like Install-Module that let you easily download and install additional PowerShell modules, extending your PowerShell with new commands and capabilities.

To see this in action, here is an example that downloads and installs the QRCodeGenerator module which generates various QR codes, i.e. for Twitter profiles:

 
# install new PowerShell module from PowerShell Gallery
PS> Install-Module -Name QRCodeGenerator -Scope CurrentUser 

# use one of the newly added commands to create a QR code for Twitter profiles
PS> New-QRCodeTwitter  -ProfileName tobiaspsp -Show  
 

When you scan the created QR code with your smartphone camera, you can visit the Twitter profile encoded in the QR code. Likewise, the other QR code types provide directions to a location or add contacts to your address book:

 
PS> Get-Command -Module QRCodeGenerator -CommandType function

CommandType     Name                          Version    Source
-----------     ----                          -------    ------   
Function        New-PSOneQRCodeGeolocation    2.2        QRCodeGenerator
Function        New-PSOneQRCodeTwitter        2.2        QRCodeGenerator
Function        New-PSOneQRCodeVCard          2.2        QRCodeGenerator
Function        New-PSOneQRCodeWifiAccess     2.2        QRCodeGenerator    
 

If you run into issues with the newly added module, one reason can be that your PowerShellGet module is outdated. If you are still using the ancient PowerShellGet version 1.0.0.1, you may run into a nasty bug.

When modules use only major and minor version numbers in their manifest file, Install-Module installs them into subfolders with 3-digit version numbers. This leaves the installed module unusable.

That’s why it is important to keep modules up-to-date. The more recent versions of PowerShellGet fixed this bug. Let’s take a look at how you check and update modules.

First, find out your current version of a module, i.e. PowerShellGet:

 
PS> Get-Module -Name PowerShellGet -ListAvailable


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands     
---------- -------    ----                                ---------------- 
Script     2.2.1      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module...}
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module...}  
 

In this example, there are two different versions of the PowerShellGet module installed: the initial release version 1.0.0.1, and an updated version 2.2.1. To find out which version you are using, try this:

 
PS> Import-Module -Name PowerShellGet

PS> Get-Module -Name PowerShellGet

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.2.1      PowerShellGet                       {Find-Command, Find-DscResource, Find-Module...}
 

Next, check to see if there is a newer version available (this requires that the module is made available through the official PowerShell Gallery which isn’t true for all modules. If your module isn’t available here, you need to check with the entity that originally supplied the module):

 
PS> Find-Module -Name PowerShellGet

Version Name          Repository Description           
------- ----          ---------- -----------                                              
2.2.3   PowerShellGet PSGallery  PowerShell module with commands for discovering, installing, upd...  
 

If there is a newer version available, try updating the module first:

 

PS> Update-Module -Name PowerShellGet 

PS> Get-Module -Name PowerShellGet -ListAvailable

    Directory: C:\Users\tobia\OneDrive\Dokumente\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands 
---------- -------    ----                                -----------   
Script     2.2.3      PowerShellGet                       {Find-Command, Find-DSCResource, Find-M...}


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------                        
Script     2.2.1      PowerShellGet                       {Find-Command, Find-DSCResource, Find-M...}
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-M...} 
 

Update-Module requires that the module was initially installed via Install-Module. If so, PowerShell knows the original source repository and updates the module automatically.

If Update-Module fails, try and re-install the module using the -Force parameter. If that still fails, add the -SkipPublisherCheck parameter:

 
PS> Install-Module -Name PowerShellGet -Scope CurrentUser -Force -SkipPublisherCheck 
 

To verify the success, make sure the latest version is loaded:

 
PS> Import-Module -Name PowerShellGet -Force -PassThru

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------                          
Script     2.2.3      PowerShellGet                       {Find-Command, Find-DscResource, Find-Mo...
 

Twitter This Tip! ReTweet this Tip!

Anonymous