Skip to content

Instantly share code, notes, and snippets.

@Sarafian
Created December 1, 2016 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sarafian/2c614cb18bd38dffa1208fbeddc294cb to your computer and use it in GitHub Desktop.
Save Sarafian/2c614cb18bd38dffa1208fbeddc294cb to your computer and use it in GitHub Desktop.
Show powershell module's (loaded and available) organized by Name, Version and Location
<#
.Synopsis
Reports modules
.DESCRIPTION
Reports modules
.EXAMPLE
Show-ModuleVersion
.EXAMPLE
Show-ModuleVersion -ListAvailable
.EXAMPLE
Show-ModuleVersion -ListAvailable -Name Pester
#>
function Global:Show-ModuleVersion
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[string]$Name=$null,
[Parameter(Mandatory=$false)]
[switch]$ListAvailable=$false
)
if($Name)
{
$modules=Get-Module -Name $Name -ListAvailable:$ListAvailable
}
else
{
$modules=Get-Module -ListAvailable:$ListAvailable
}
$groups=$modules |Sort-Object -Property Name|Group-Object -Property Name
$groups|ForEach-Object {
$_.Group | Sort-Object -Property Version -Descending | Select-Object Name,Version,@{Name="Profile";Expression={
switch ($_.ModuleBase)
{
{$_ -like "$($env:SystemRoot)*" } {
"System"
break
}
{$_ -like "$($env:USERPROFILE)*" } {
"Profile"
break
}
{$_ -like "$(${env:ProgramFiles(x86)})*" } {
"Program Files (x86)"
break
}
{$_ -like "$($env:ProgramFiles)*" } {
"Program Files"
break
}
Default {"Unknown"}
}
}},ModuleBase
}
}
@Sarafian
Copy link
Author

Sarafian commented Dec 1, 2016

For example on my client I've update the Pester module. This is how it would look

PS C:\Users\asarafian> Show-ModuleVersion -ListAvailable Pester

Name   Version Profile       ModuleBase
----   ------- -------       ----------
Pester 3.4.3   Profile       C:\Users\asarafian\Documents\WindowsPowerShell\Modules\Pester\3.4.3
Pester 3.3.5   Program Files C:\Program Files\WindowsPowerShell\Modules\Pester\3.3.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment