Skip to content

Commit 590f16d

Browse files
committed
Update Update-AllPowerShellModules.ps1
1 parent 95f4b62 commit 590f16d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Update-AllPowerShellModules.ps1

+20-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function Remove-OldPowerShellModules {
5252
$oldVersions = Get-InstalledModule -Name $ModuleName -AllVersions -ErrorAction Stop | Where-Object { $_.Version -ne $GalleryVersion }
5353

5454
foreach ($oldVersion in $oldVersions) {
55-
Write-Host -ForegroundColor Cyan "$ModuleName - Uninstall previous version ($($oldVersion.Version))"
55+
Write-Host -ForegroundColor Cyan "$ModuleName - Uninstall previous version" -NoNewline
56+
Write-Host -ForegroundColor White " ($($oldVersion.Version))"
57+
5658
if (-not($SimulationMode)) {
5759
Remove-Module $ModuleName -ErrorAction SilentlyContinue
5860
Uninstall-Module $oldVersion -Force -ErrorAction Stop
@@ -66,7 +68,7 @@ function Remove-OldPowerShellModules {
6668

6769
if ($IncludedModules) {
6870
Write-Host -ForegroundColor Cyan "Get PowerShell modules like $IncludedModules"
69-
$modules = Get-InstalledModule | Where-Object { $_.Name -like $IncludedModules}
71+
$modules = Get-InstalledModule | Where-Object { $_.Name -like $IncludedModules }
7072
}
7173
else {
7274
Write-Host -ForegroundColor Cyan 'Get all PowerShell modules'
@@ -131,19 +133,27 @@ foreach ($module in $modules.Name) {
131133
}
132134
}
133135
elseif ($moduleGalleryInfo.Version -eq $currentVersion) {
134-
Write-Host -ForegroundColor Green "$module already in latest version: $currentVersion - Release date: $publishedDate"
136+
Write-Host -ForegroundColor Green "$module - already in latest version: " -NoNewline
137+
Write-Host -ForegroundColor White "$currentVersion" -NoNewline
138+
Write-Host -ForegroundColor Green " - Release date:" -NoNewline
139+
Write-Host -ForegroundColor White " $publishedDate"
135140
}
136141
elseif ($currentVersion.count -gt 1) {
137-
Write-Host -ForegroundColor Yellow "$module is installed in $($currentVersion.count) versions (versions: $($currentVersion -join ' | '))"
138-
Write-Host -ForegroundColor Cyan "$module - Uninstall previous $module version(s) below the latest version ($($moduleGalleryInfo.Version))"
142+
Write-Host -ForegroundColor Yellow "$module is installed in $($currentVersion.count) versions:" -NoNewline
143+
Write-Host -ForegroundColor White " $($currentVersion -join ' | ')"
144+
Write-Host -ForegroundColor Cyan "$module - Uninstall previous $module version(s) below the latest version" -NoNewline
145+
Write-Host -ForegroundColor White " ($($moduleGalleryInfo.Version))"
139146

140147
Remove-OldPowerShellModules -ModuleName $module -GalleryVersion $moduleGalleryInfo.Version
141148

142149
# Check again the current Version as we uninstalled some old versions
143150
$currentVersion = (Get-InstalledModule -Name $module).Version
144151

145152
if ($moduleGalleryVersion -ne $currentVersion) {
146-
Write-Host -ForegroundColor Cyan "$module - Install from PowerShellGallery version $($moduleGalleryInfo.Version) - Release date: $publishedDate"
153+
Write-Host -ForegroundColor Cyan "$module - Install from PowerShellGallery version" -NoNewline
154+
Write-Host -ForegroundColor White " $($moduleGalleryInfo.Version)" -NoNewline
155+
Write-Host -ForegroundColor Cyan " - Release date:" -NoNewline
156+
Write-Host -ForegroundColor White " $publishedDate"
147157

148158
if (-not($SimulationMode)) {
149159
try {
@@ -162,9 +172,10 @@ foreach ($module in $modules.Name) {
162172
Write-Host -ForegroundColor Yellow "$module - the current version $currentVersion is newer than the version available on PowerShell Gallery $($moduleGalleryInfo.Version) (Release date: $publishedDate). Sometimes happens when you install a module from another repository or via .exe/.msi or if you change the version number manually."
163173
}
164174
elseif ([version]$currentVersion -lt [version]$moduleGalleryVersion) {
165-
Write-Host -ForegroundColor Cyan "$module - Update from PowerShellGallery version " -NoNewline
166-
Write-Host -ForegroundColor White "$currentVersion -> $($moduleGalleryInfo.Version) " -NoNewline
167-
Write-Host -ForegroundColor Cyan "- Release date: $publishedDate"
175+
Write-Host -ForegroundColor Cyan "$module - Update from PowerShellGallery version" -NoNewline
176+
Write-Host -ForegroundColor White " $currentVersion -> $($moduleGalleryInfo.Version)" -NoNewline
177+
Write-Host -ForegroundColor Cyan " - Release date:" -NoNewline
178+
Write-Host -ForegroundColor White " $publishedDate"
168179

169180
if (-not($SimulationMode)) {
170181
try {

0 commit comments

Comments
 (0)