From f04b82af5f243c9758acca767211e0ca4f7ed7e6 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 6 Oct 2018 07:31:25 -0700 Subject: [PATCH] allow dynamic paramter to be returned even if path matches nothing --- .../engine/SessionStateContent.cs | 8 +------- .../Get-Content.Tests.ps1 | 9 +++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/System.Management.Automation/engine/SessionStateContent.cs b/src/System.Management.Automation/engine/SessionStateContent.cs index dc4d1f3365c..6e845601d5e 100644 --- a/src/System.Management.Automation/engine/SessionStateContent.cs +++ b/src/System.Management.Automation/engine/SessionStateContent.cs @@ -275,13 +275,7 @@ internal object GetContentReaderDynamicParameters( out provider, out providerInstance); - if (providerPaths.Count > 0) - { - // Get the dynamic parameters for the first resolved path - - return GetContentReaderDynamicParameters(providerInstance, providerPaths[0], newContext); - } - return null; + return GetContentReaderDynamicParameters(providerInstance, path, newContext); } // GetContentReaderDynamicParameters /// diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 index aa1650e0711..eac53dd780f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 @@ -278,6 +278,15 @@ baz } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.GetContentCommand" } + It "Should throw ItemNotFound when path matches no files with " -TestCases @( + @{ variation = "no additional parameters"; params = @{} }, + @{ variation = "dynamic parameter" ; params = @{ Raw = $true }} + ) { + param($params) + + { Get-Content -Path "/DoesNotExist*.txt" @params -ErrorAction Stop } | Should -Throw -ErrorId "ItemNotFound,Microsoft.PowerShell.Commands.GetContentCommand" + } + Context "Check Get-Content containing multi-byte chars" { BeforeAll { $firstLine = "Hello,World"