Skip to content

Commit 0638701

Browse files
author
Robin Stolpe
committed
update
1 parent 33af19d commit 0638701

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

.src/Public/Function/Update-RSModule.ps1

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,24 @@
126126
# Start looping trough every module that are stored in the string Module
127127
foreach ($m in $Module.Split()) {
128128
Write-Verbose "Checks if $($m) are installed"
129-
$MostRecentVersion = $null
130129
if ($m -in $InstalledModules.Name) {
131130

132131
# Getting the latest installed version of the module
133132
Write-Verbose "Collecting all installed version of $($m)..."
134-
$GetAllInstalledVersions = Get-InstalledModule -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object -ExpandProperty Version
135-
[version]$MostRecentVersion = $GetAllInstalledVersions[0]
133+
$GetAllInstalledVersions = Get-InstalledModule -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version
134+
[version]$LatestInstalledVersion = $($GetAllInstalledVersions | Select-Object Version -First 1).version
136135

137136
# Collects the latest version of module from the source where the module was installed from
138-
Write-Verbose "Looking up the latest version of $($m)..."
139-
$CollectLatestVersion = Find-Module -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object -First 1
137+
Write-Output "Looking up the latest version of $($m)..."
138+
[version]$CollectLatestVersion = $(Find-Module -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version -First 1).version
140139

141140
# Looking if the version of the module are the latest version, it it's not the latest it will install the latest version.
142-
if ([version]$MostRecentVersion -lt $CollectLatestVersion.Version) {
141+
if ($LatestInstalledVersion -lt $CollectLatestVersion) {
143142
try {
144-
Write-Output "Found a newer version of $($m), version $($CollectLatestVersion.Version)"
145-
Write-Output "Updating $($m) from $($MostRecentVersion) to version $($CollectLatestVersion.Version)..."
143+
Write-Output "Found a newer version of $($m), version $($CollectLatestVersion)"
144+
Write-Output "Updating $($m) from $($LatestInstalledVersion) to version $($CollectLatestVersion)..."
146145
Update-Module -Name $($m) -Scope $Scope -Force
147-
Write-Output "$($m) has now been updated to version $($CollectLatestVersion.Version)!`n"
146+
Write-Output "$($m) has now been updated to version $($CollectLatestVersion)!`n"
148147
}
149148
catch {
150149
Write-Error "$($PSItem.Exception)"
@@ -207,4 +206,6 @@
207206
}
208207
}
209208
Write-Output "`n---/// Script Finished! ///---"
210-
}
209+
}
210+
211+
Update-RSModule -UninstallOldVersion -Scope CurrentUser

0 commit comments

Comments
 (0)