Created
October 14, 2016 11:10
-
-
Save Sarafian/2d705bec07712cfe000f57543b61217b to your computer and use it in GitHub Desktop.
Compare PowerShell system module with their PowerShell gallery counterparts
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
<# | |
.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