Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > PowerShell to Update your PowerShell Modules
May 10
PowerShell to Update your PowerShell Modules

One of the great things about PowerShell is how easy it is to extend it with modules. The only thing greater is all the modules that are out there. I have a bunch that I use on a daily basis, I couldn’t live without them. But in today’s rapid development cycle it’s easy to get behind on your favorite modules. I wrote this blog post to help people keep up with the Office 365 related PowerShell modules I use, but from what I understand there are other technologies out there with their own suite of modules that people want to keep up with. To help those folks out, I thought I’d share how I keep up to date with my favorite modules.

This method only works with modules that are installed from a repository. If a module has been installed some other way, like with an MSI or EXE you’re out of luck.

The key to this magic is a group of cmdlets that deal with modules, particularly Find-Module and Update-Module. That’s why it only works with modules installed from a repository with Install-Module. To find the relevant cmdlets run:

Get-Command -Noun module

and

Get-Command -Noun InstalledModule

Here’s how I stitch them together to get a list of modules that have updates:

Get-InstalledModule | foreach { $b = (find-module $_.name).version ; if ($b -ne $_.version) { Write-host "$($_.name) has an update from $($_.version) to $b" } }

Let’s break that down.

Get-InstalledModule

Gets all of the modules that have been installed from a repository.

| foreach

Pipes them all l through a foreach loop.

$b = (find-module $_.name).version

Grabs the current published version of the module in the loop.

if ($b -ne $_.version)

Checks to see if the published version is the same as the Version property of the installed module.

{ Write-host "$($_.name) has an update from $($_.version) to $b" }

If they are not equal, it writes out the module name, the installed version, and the current published version.

It looks like this:

image 

In screenshot I ran Get-InstalledModule to show its full output, then the full command and its output.

Now we know which modules can be updated. We can update an individual module like this:

Update-Module SharePointPnPPowerShellOnline –Force

That will update the SharePointPnPPowerShellOnline module and won’t yell at us because it’s replacing an existing one. If the module has been installed with the “AllUsers” scope (the default) you’ll need to run the Update-Module cmdlet in an Administrator prompt.

image 

Now if I run my command it will not report that that the SharePointPnPPowerShellOnline module has an update.

image 

It would be easy to replace the “Write-Host…” part of the command with “Update-Module $_.name” and have it update them automatically. I didn’t do that mainly because the PowerApps modules’ install is a little hinky and requires some extra handholding. If you don’t have them installed, or you want to upgrade them manually first, you could have the command update them automatically.

I hope you’ve found this helpful.

tk

ShortURL: https://www.toddklindt.com/PoshUpdateModules

Comments

Political Social Network

Thanks for sharing such beautiful and nice information with us
and I hope you will also share again such Nice info, I am very thankful to you for providing knowledge full information with us. https://www.polltical.com
 on 5/14/2019 2:55 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 SysKit