8000 Fix issue with Get-Process -Module failing to stop when piped to Sele… · xtqqczze/PowerShell-PowerShell@bde7bd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit bde7bd6

Browse files
ArmaanMcleodxtqqczze
authored andcommitted
Fix issue with Get-Process -Module failing to stop when piped to Select-Object (PowerShell#15682)
1 parent afc61a9 commit bde7bd6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ protected override void ProcessRecord()
640640
WriteNonTerminatingError(process, ex, ProcessResources.CouldNotEnumerateModules, "CouldNotEnumerateModules", ErrorCategory.PermissionDenied);
641641
}
642642
}
643+
catch (PipelineStoppedException)
644+
{
645+
throw;
646+
}
643647
catch (Exception exception)
644648
{
645649
WriteNonTerminatingError(process, exception, ProcessResources.CouldNotEnumerateModules, "CouldNotEnumerateModules", ErrorCategory.PermissionDenied);

test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ Describe "Get-Process" -Tags "CI" {
8787
{ Get-Process -Module -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateModules,Microsoft.PowerShell.Commands.GetProcessCommand"
8888
}
8989

90+
It "Should not fail to stop Get-Process with -Module when piped to Select-Object" {
91+
Get-Process -Module -Id $PID -ErrorVariable errs | Select-Object -First 1
92+
$errs | Should -HaveCount 0
93+
}
94+
9095
It "Should fail to run Get-Process with -FileVersionInfo without admin" -Skip:(!$IsWindows) {
9196
{ Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateFileVer,Microsoft.PowerShell.Commands.GetProcessCommand"
9297
}

0 commit comments

Comments
 (0)
0