Created
July 1, 2016 01:37
-
-
Save juneb/4d125cf03a3dcfc52a34698e03f7f91f to your computer and use it in GitHub Desktop.
Gets the newest version of each module on the system.
This file contains 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 | |
Gets the newest version of each module on the system. | |
.DESCRIPTION | |
Gets the newest version of each module on the system. Designed for PowerShell 5.0 where you can have multiple versions of the same module in different directories or in the same directory (in different version subdirectories). Returns only one version of each module. | |
.EXAMPLE | |
$LatestModules = .\Get-LatestModule.ps1 | |
.NOTES | |
=========================================================================== | |
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.99 | |
Created on: 12/27/2015 2:22 PM | |
Created by: June Blender | |
Organization: SAPIEN Technologies, Inc. | |
Filename: Get-LatestModule.ps1 | |
=========================================================================== | |
#> | |
# Holds path to latest version of the module on the system | |
$one = $many = $LatestModules = @() | |
$nameGroups = Get-Module -ListAvailable | Group-Object Name | |
$nameGroups | ForEach-Object { | |
if ($_.count -eq 1) | |
{ | |
$one += $_ | |
} | |
else | |
{ | |
$many += $_ | |
} | |
} | |
$LatestModules = $one.Group | |
$many | ForEach-Object { | |
$LatestModules += ($_.group | Sort-Object -Property Version -Descending)[0] | |
} | |
return $LatestModules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment