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 {
        $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!

Copyright 2012 PowerShell.com. All rights reserved.