PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Geek Sync Live

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

Latest Blog Posts

04-29-2016 - Free ebook: IoT
04-29-2016 - Keeping Your Modules Up-To-Date
04-28-2016 - Better Prompting for Mandatory Parameters

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Keeping Your Modules Up-To-Date

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 powershellgallery.com.

Get-InstalledModule | ForEach-Object {
    try
    {
        $module = Find-Module -Name $_.Name -ErrorAction Stop
        $newVersion = $module.Version
        $needsUpdate = $_.Version -lt $newVersion
    }
    catch
    {
        $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 |
  Out-GridView

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 0.2.0.0  0.2.0.0            
xRobocopy                     True 1.1.0.0  1.2.0.0            
xWebAdministration            True 1.8.0.0  1.9.0.0            
CommunityAnalyzerRules        True 0.0.0.1  no longer available
FabrikamAnalyzerRules         True 0.0.0.1  no longer available
ISESteroids                   True 2.3.0.46 2.3.0.64           
nScriptAnalyzerRules         False 0.1      0.1                
NtpTime                      False 1.1      1.1                
Pscx                         False 3.2.1.0  3.2.1.0            
PSScriptAnalyzer              True 1.1.0    1.4.0              
ScriptAnalyzer                True 0.5.1.0  no longer available
xDSCResourceDesigner          True 1.6.0.0  1.7.0.0 
 

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.