Keeping Your Modules Up-To-Date

by Apr 29, 2016

Once you start downloading modules from the PowerShell Gallery (or via PowerShellGet in general), you get version control automatically. You can always review the modules that were installed, and compare their versions with the versions available in the repository.

This way, it's easy to find out the modules that need an update. The following code assumes that you know the PowerShell Gallery already. If not, visit

Get-InstalledModule | ForEach-Object {
        $module = Find-Module -Name $_.Name -ErrorAction Stop
        $newVersion = $module.Version
        $needsUpdate = $_.Version -lt $newVersion
        $newVersion = 'no longer available'
        $needsUpdate = $true
    $_ | Add-Member -MemberType NoteProperty -Name VersionAvailable $newVersion 
    $_ | Add-Member -MemberType NoteProperty -Name NeedsUpdate $needsUpdate 
  } |
  Select-Object -Property Name, NeedsUpdate, Version, VersionAvailable |

When you run this code, you get a list of modules that were installed via PowerShellGet, and version information that tells whether a module needs an update. The output looks similar to this:

Name                   NeedsUpdate Version  VersionAvailable   
----                   ----------- -------  ----------------   
Pester                       False 3.4.0    3.4.0              
xDefender                    False            
xRobocopy                     True            
xWebAdministration            True            
CommunityAnalyzerRules        True  no longer available
FabrikamAnalyzerRules         True  no longer available
ISESteroids                   True           
nScriptAnalyzerRules         False 0.1      0.1                
NtpTime                      False 1.1      1.1                
Pscx                         False            
PSScriptAnalyzer              True 1.1.0    1.4.0              
ScriptAnalyzer                True  no longer available
xDSCResourceDesigner          True 

Twitter This Tip! ReTweet this Tip!