File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
test/UninstallPSResourceTests Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,23 @@ private bool UninstallPkgHelper(out List<ErrorRecord> errRecords)
258
258
}
259
259
}
260
260
261
+ // If we had packages but didn't uninstall any (e.g., due to version/prerelease filters), write a warning
262
+ if ( currentUninstalledDirCount == 0 && totalDirs > 0 )
263
+ {
264
+ string warningMessage = Prerelease
265
+ ? $ "No prerelease versions of '{ String . Join ( ", " , Name ) } ' were found to uninstall."
266
+ : $ "No packages matching the specified criteria for '{ String . Join ( ", " , Name ) } ' were found to uninstall.";
267
+
268
+ if ( Version != null && ! Version . Trim ( ) . Equals ( "*" ) )
269
+ {
270
+ warningMessage = Prerelease
271
+ ? $ "No prerelease versions of '{ String . Join ( ", " , Name ) } ' matching version '{ Version } ' were found to uninstall."
272
+ : $ "No packages of '{ String . Join ( ", " , Name ) } ' matching version '{ Version } ' were found to uninstall.";
273
+ }
274
+
275
+ WriteWarning ( warningMessage ) ;
276
+ }
277
+
261
278
return successfullyUninstalled ;
262
279
}
263
280
Original file line number Diff line number Diff line change @@ -235,6 +235,23 @@ Describe 'Test Uninstall-PSResource for Modules' -tags 'CI' {
235
235
$stableVersionPkgs.Count | Should - Be 2
236
236
}
237
237
238
+ It " Write warning when using -Prerelease flag with only stable versions installed" {
239
+ # Install a stable version
240
+ Install-PSResource - Name $testModuleName - Version " 5.0.0.0" - Repository $PSGalleryName - TrustRepository
241
+
242
+ # Try to uninstall with -Prerelease flag, should show warning
243
+ Uninstall-PSResource - Name $testModuleName - Prerelease - SkipDependencyCheck - WarningVariable warn - WarningAction SilentlyContinue
244
+
245
+ # Module should still be present
246
+ $res = Get-InstalledPSResource - Name $testModuleName - Version " 5.0.0.0"
247
+ $res.Name | Should - Be $testModuleName
248
+ $res.Version | Should - Be " 5.0.0.0"
249
+
250
+ # Warning should have been written
251
+ $warn.Count | Should - Be 1
252
+ $warn [0 ] | Should -Match " No prerelease versions"
253
+ }
254
+
238
255
It " Uninstall module using -WhatIf, should not uninstall the module" {
239
256
Start-Transcript .\testUninstallWhatIf.txt
240
257
Uninstall-PSResource - Name $testModuleName - WhatIf - SkipDependencyCheck
You can’t perform that action at this time.
0 commit comments