Skip to content

Commit aff2147

Browse files
committed
Update Update-AllPowerShellModules.ps1
1 parent 39d9e7a commit aff2147

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Update-AllPowerShellModules.ps1

+18-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function Remove-OldPowerShellModules {
6767
}
6868

6969
if ($IncludedModules) {
70-
$modules = Get-InstalledModule | Where-Object { $IncludedModules -contains $_.Name }
70+
$modules = Get-InstalledModule | Where-Object { $_.Name -like $IncludedModules}
7171
}
7272
else {
7373
$modules = Get-InstalledModule
@@ -98,8 +98,22 @@ foreach ($module in $modules.Name) {
9898
}
9999
catch {
100100
Write-Warning "$module not found in the PowerShell Gallery. $($_.Exception.Message)"
101+
continue
101102
}
102103

104+
# $current version can also be a version follow by -preview
105+
if ($currentVersion -like '*-preview') {
106+
Write-Warning "The module installed is a preview version, it will not tested by this script"
107+
}
108+
109+
if ($moduleGalleryInfo.Version -like '*-preview') {
110+
Write-Warning "The module in PowerShell Gallery is a preview version, it will not tested bt this script"
111+
continue
112+
}
113+
else {
114+
$moduleGalleryVersion = $moduleGalleryInfo.Version
115+
}
116+
103117
# Convert published date to YYYY/MM/DD HH:MM:SS format
104118
$publishedDate = [datetime]$moduleGalleryInfo.PublishedDate
105119
$publishedDate = $publishedDate.ToString("yyyy/MM/dd HH:mm:ss")
@@ -128,7 +142,7 @@ foreach ($module in $modules.Name) {
128142
# Check again the current Version as we uninstalled some old versions
129143
$currentVersion = (Get-InstalledModule -Name $module).Version
130144

131-
if ($moduleGalleryInfo.Version -ne $currentVersion) {
145+
if ($moduleGalleryVersion -ne $currentVersion) {
132146
Write-Host -ForegroundColor Cyan "$module - Install from PowerShellGallery version $($moduleGalleryInfo.Version) - Release date: $publishedDate"
133147

134148
if (-not($SimulationMode)) {
@@ -144,10 +158,10 @@ foreach ($module in $modules.Name) {
144158
}
145159
}
146160
# https://invoke-thebrain.com/2018/12/comparing-version-numbers-powershell/
147-
elseif ([version]$currentVersion -gt [version]$moduleGalleryInfo.Version) {
161+
elseif ([version]$currentVersion -gt [version]$moduleGalleryVersion) {
148162
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."
149163
}
150-
elseif ([version]$currentVersion -lt [version]$moduleGalleryInfo.Version) {
164+
elseif ([version]$currentVersion -lt [version]$moduleGalleryVersion) {
151165
Write-Host -ForegroundColor Cyan "$module - Update from PowerShellGallery version " -NoNewline
152166
Write-Host -ForegroundColor White "$currentVersion -> $($moduleGalleryInfo.Version) " -NoNewline
153167
Write-Host -ForegroundColor Cyan "- Release date: $publishedDate"

0 commit comments

Comments
 (0)