@@ -67,7 +67,7 @@ function Remove-OldPowerShellModules {
67
67
}
68
68
69
69
if ($IncludedModules ) {
70
- $modules = Get-InstalledModule | Where-Object { $IncludedModules -contains $ _.Name }
70
+ $modules = Get-InstalledModule | Where-Object { $_.Name -like $IncludedModules }
71
71
}
72
72
else {
73
73
$modules = Get-InstalledModule
@@ -98,8 +98,22 @@ foreach ($module in $modules.Name) {
98
98
}
99
99
catch {
100
100
Write-Warning " $module not found in the PowerShell Gallery. $ ( $_.Exception.Message ) "
101
+ continue
101
102
}
102
103
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
+
103
117
# Convert published date to YYYY/MM/DD HH:MM:SS format
104
118
$publishedDate = [datetime ]$moduleGalleryInfo.PublishedDate
105
119
$publishedDate = $publishedDate.ToString (" yyyy/MM/dd HH:mm:ss" )
@@ -128,7 +142,7 @@ foreach ($module in $modules.Name) {
128
142
# Check again the current Version as we uninstalled some old versions
129
143
$currentVersion = (Get-InstalledModule - Name $module ).Version
130
144
131
- if ($moduleGalleryInfo .Version -ne $currentVersion ) {
145
+ if ($moduleGalleryVersion -ne $currentVersion ) {
132
146
Write-Host - ForegroundColor Cyan " $module - Install from PowerShellGallery version $ ( $moduleGalleryInfo.Version ) - Release date: $publishedDate "
133
147
134
148
if (-not ($SimulationMode )) {
@@ -144,10 +158,10 @@ foreach ($module in $modules.Name) {
144
158
}
145
159
}
146
160
# 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 ) {
148
162
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."
149
163
}
150
- elseif ([version ]$currentVersion -lt [version ]$moduleGalleryInfo .Version ) {
164
+ elseif ([version ]$currentVersion -lt [version ]$moduleGalleryVersion ) {
151
165
Write-Host - ForegroundColor Cyan " $module - Update from PowerShellGallery version " - NoNewline
152
166
Write-Host - ForegroundColor White " $currentVersion -> $ ( $moduleGalleryInfo.Version ) " - NoNewline
153
167
Write-Host - ForegroundColor Cyan " - Release date: $publishedDate "
0 commit comments