Created
November 29, 2018 11:03
-
-
Save Splaxi/008e0ae70650af74d9d399b8dbe857b3 to your computer and use it in GitHub Desktop.
Test all modules versions against PSGallery and Updated them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Inspired from the work of Jack (@sharepointjack) - http://sharepointjack.com/2017/powershell-script-to-remove-duplicate-old-modules | |
| #Will test all installed modules against the PSGallery and see if a never version is available. | |
| #If newer version is available it will update it | |
| $mods = Get-InstalledModule | |
| foreach ($mod in $mods) { | |
| Write-Host "Checking $($mod.name)" | |
| $latestAvailable = Find-Module $mod.Name | |
| if ($mod.version -eq $latestAvailable.version) { | |
| $color = "green" | |
| $text = "Latest available version match current installed" | |
| } | |
| else { | |
| $color = "magenta" | |
| $text = "Latest available version is higher than the current installed. Will install latest version " | |
| } | |
| Write-Host "$($mod.Name) - $($mod.version) [$text $($latestAvailable.version)]" -foregroundcolor $color | |
| if($color -eq "magenta") { | |
| Update-Module $mod.Name -Force | |
| } | |
| Write-Host "------------------------" | |
| } | |
| Write-Host "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment