Fix issue with Get-Process -Module failing to stop when piped to Select-Object (#15682)

This commit is contained in:
Armaan Mcleod 2021-08-13 02:06:58 +10:00 committed by GitHub
parent e2c23fc5bd
commit b70f06ccc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -640,6 +640,10 @@ namespace Microsoft.PowerShell.Commands
WriteNonTerminatingError(process, ex, ProcessResources.CouldNotEnumerateModules, "CouldNotEnumerateModules", ErrorCategory.PermissionDenied);
}
}
catch (PipelineStoppedException)
{
throw;
}
catch (Exception exception)
{
WriteNonTerminatingError(process, exception, ProcessResources.CouldNotEnumerateModules, "CouldNotEnumerateModules", ErrorCategory.PermissionDenied);

View file

@ -87,6 +87,11 @@ Describe "Get-Process" -Tags "CI" {
{ Get-Process -Module -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateModules,Microsoft.PowerShell.Commands.GetProcessCommand"
}
It "Should not fail to stop Get-Process with -Module when piped to Select-Object" {
Get-Process -Module -Id $PID -ErrorVariable errs | Select-Object -First 1
$errs | Should -HaveCount 0
}
It "Should fail to run Get-Process with -FileVersionInfo without admin" -Skip:(!$IsWindows) {
{ Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateFileVer,Microsoft.PowerShell.Commands.GetProcessCommand"
}