Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Check for Module Updates

Posted on February 17, 2017

It seems to me that the topic of finding or detecting module updates on the PowerShell Gallery has gotten a lot of interest over the last few days. So I thought I'd contribute my bit of code to check currently installed modules against their online versions in the PowerShell Gallery.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

I have a PowerShell script I called Check-ModuleUpdate, which you can find as a gist on Github.

https://gist.github.com/jdhitsolutions/8a49a59c5dd19da9dde6051b3e58d2d0

The script gets all currently installed scripts and filters out those that do not have a value for the RepositorySourceLocation.  On my computer I've only installed from the PSGallery so the links are all the same. If you will have multiple locations you'll need to modify the code, especially with Find-Module to accommodate the differences.

The script then uses a ForEach loop to get the online version so that it can compare it with the installed version. The script writes a custom object to the pipeline. I've also included code to indicate if you have multiple versions of a module installed.

image

Another use is to pipe to Out-Gridview and use that as an object picker to update selected modules.

C:\scripts\Check-ModuleUpdate.ps1 | 
Out-Gridview -title "Select modules to update" -PassThru | 
foreach { 
    Write-Host "Updating $($_.name)" -foreground Cyan
    update-module $_.name -force 
}

I'll admit this isn't a perfect script. You might even prefer to have it as a function. So I'll leave enhancements and updates to you.


Behind the PowerShell Pipeline

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
  • Print (Opens in new window) Print
  • Email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

8 thoughts on “Check for Module Updates”

  1. Christophe says:
    February 17, 2017 at 12:13 pm

    hello, really nice ! i added this :
    Path = $module.ModuleBase
    At end of the pscustomobject.
    Like this if i have more than one version of a module, i can see where they are ..

    1. Jeffery Hicks says:
      February 17, 2017 at 1:45 pm

      Good call. I thought about this as well, got sidetracked, and never added it. I think I’ll update my version as well.

  2. Gyzmos says:
    February 17, 2017 at 1:57 pm

    I’m already using your function compare-module which is great.
    Doesn’t this have the same functionality as Check-ModuleUpdate or am I missing something..?

    1. Jeffery Hicks says:
      February 17, 2017 at 2:14 pm

      I’m sure there are some similarities.

  3. APraestegaard says:
    February 27, 2017 at 11:08 am

    You might find ‘Get-InstalledModule’ relevant

  4. Jeffery Hicks says:
    February 27, 2017 at 2:28 pm

    That is indeed helpful. Not sure why I missed that command. Unless it is something the product team slipped into 5.1 release. I don’t recall it in v5.

  5. Bryan Dady says:
    March 28, 2017 at 9:06 am

    I found the $gallery = $modules.where({$_.repositorysourcelocation}) check errored out in PS4, so I had replaced it with $gallery = $modules.where({$_.PrivateData}), but thanks to APraestegaard’s suggestion above, I’m changing it to rely on the collection from Get-InstalledModule (which appears to be available in my PS 4.0).

    I also moved the PSGallery check out of the loop, finding it more efficient to load a full inventory from the online gallery, and then iterate through comparing my local modules with the version of the gallery module, instead of querying via Find-Module for each installed module (I found the 1 full Find-Module -Repository PSGallery took my about 10 seconds, while each individual Find-Module -name $module.name -Repository PSGallery took nearly 7 sec. x the dozen or so locally installed modules).

    1. Jeffery Hicks says:
      March 28, 2017 at 1:20 pm

      Using a GitHub gist is handy but much harder to integrate changes like yours. If you can, enter your changes as a comment on the gist (https://gist.github.com/jdhitsolutions/8a49a59c5dd19da9dde6051b3e58d2d0) and I’ll see about updating it.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2026 The Lonely Administrator | Powered by SuperbThemes!
%d