Skip to content

Instantly share code, notes, and snippets.

@Sarafian
Created October 14, 2016 11:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sarafian/2d705bec07712cfe000f57543b61217b to your computer and use it in GitHub Desktop.
Save Sarafian/2d705bec07712cfe000f57543b61217b to your computer and use it in GitHub Desktop.
Compare PowerShell system module with their PowerShell gallery counterparts
<#
.Synopsis
Compares system modules with available ones on powershell gallery
.DESCRIPTION
Compares system modules with available ones on powershell gallery
.EXAMPLE
Compare-SystemModuleWithGallery
.Link
http://mikefrobbins.com/2016/06/09/update-manually-installed-powershell-modules-from-the-powershell-gallery/
#>
Function Global:Compare-SystemModuleWithGallery
{
Get-Module -ListAvailable |
Where-Object ModuleBase -like $env:ProgramFiles\WindowsPowerShell\Modules\* |
Sort-Object -Property Name, Version -Descending |
Get-Unique -PipelineVariable Module |
ForEach-Object {
if (-not(Test-Path -Path "$($_.ModuleBase)\PSGetModuleInfo.xml")) {
Find-Module -Name $_.Name -OutVariable Repo -ErrorAction SilentlyContinue |
Compare-Object -ReferenceObject $_ -Property Name, Version |
Where-Object SideIndicator -eq '=>' |
Select-Object -Property Name,
@{label='InstalledVersion';expression={$Module.Version}},
@{label='Repository';expression={$Repo.Repository}},
Version
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment