Skip to content

Commit f782d0f

Browse files
committed
✨ Add outdated modules script; update other module management
1 parent 9312c79 commit f782d0f

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

Get-OutdatedModules.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<#
2+
.SYNOPSIS
3+
Returns a list of modules that have upgrades available.
4+
5+
.FUNCTIONALITY
6+
PowerShell Modules
7+
8+
.LINK
9+
Get-ModuleScope.ps1
10+
11+
.EXAMPLE
12+
Get-OutdatedModules.ps1
13+
14+
Name Scope CurrentVersion AvailableVersion
15+
---------- -------- --------------- ----------------
16+
PSReadLine AllUsers 2.3.6 2.4.5
17+
ThreadJob AllUsers 2.0.7 2.1.0
18+
#>
19+
20+
#Requires -Version 7
21+
[CmdletBinding()] Param()
22+
Get-Module -ListAvailable |
23+
Group-Object Name |
24+
ForEach-Object -Parallel {
25+
$name, $group = $_.Name, $_.Group
26+
try
27+
{[pscustomobject]@{
28+
Name = $name
29+
Scope = Get-ModuleScope.ps1 $name |Select-Object -ExpandProperty Scope
30+
CurrentVersion = $group |Measure-Object Version -Maximum |Select-Object -ExpandProperty Maximum
31+
AvailableVersion = Find-Module $name -ErrorAction Stop |Select-Object -ExpandProperty Version
32+
}}
33+
catch{}
34+
} |
35+
Where-Object {$_.CurrentVersion -lt $_.AvailableVersion}

Show-Status.ps1

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ Begin
8686

8787
function Get-PSModulesTest
8888
{{
89-
if(Get-Module -ListAvailable |
90-
ForEach-Object -Parallel {
91-
Find-Module $_.Name -EA Ignore |
92-
Where-Object Version -gt $_.Version
93-
} -ThrottleLimit 6 |
94-
Select-Object -First 1) {'psmodules'}
89+
if(Get-OutdatedModules.ps1 |Select-Object -First 1) {'psmodules'}
9590
}}
9691

9792
filter Format-Status

Uninstall-OldModules.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<#
22
.SYNOPSIS
3-
Uninstalls old module versions.
3+
Uninstalls old module versions (ignoring old Windows PowerShell modules).
44
55
.FUNCTIONALITY
66
PowerShell Modules
7+
8+
.EXAMPLE
9+
Uninstall-OldModules.ps1
10+
11+
Cleans up redundant old modules.
712
#>
813

914
#Requires -Version 3
10-
[CmdletBinding(ConfirmImpact='High',SupportsShouldProcess=$true)][OutputType([void])] Param(
15+
[CmdletBinding(ConfirmImpact='High',SupportsShouldProcess=$true)] Param(
1116
# Indicates the modules should be forced to uninstall.
1217
[switch] $Force
1318
)
1419

15-
Get-Module -List |
20+
Get-Module -ListAvailable |
1621
Where-Object {$PSVersionTable.PSVersion -lt [version]'6.0' -or $_.ModuleBase -notlike '*\WindowsPowerShell\*'} |
1722
Group-Object Name |
1823
Where-Object Count -gt 1 |

Update-Modules.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ Cleans up old modules.
44
55
.FUNCTIONALITY
66
PowerShell Modules
7+
8+
.LINK
9+
Uninstall-OldModules.ps1
10+
11+
.EXAMPLE
12+
Update-Modules.ps1
13+
14+
Updates installed modules and purges old versions.
715
#>
816

917
#Requires -Version 3
10-
[CmdletBinding()][OutputType([void])] Param()
11-
18+
[CmdletBinding()] Param()
1219
Update-Module -Force
13-
foreach($module in Get-Module -List |Group-Object Name |Where-Object Count -gt 1)
14-
{
15-
$newestversion = $module.Group.Version |Sort-Object -Descending |Select-Object -First 1
16-
foreach($oldmodule in $module.Group |Where-Object Version -lt $newestversion)
17-
{
18-
Uninstall-Module $oldmodule.Name -RequiredVersion $oldmodule.Version
19-
}
20-
}
20+
Uninstall-OldModules.ps1

0 commit comments

Comments
 (0)