From 4e5e3900f646449e91a30434dc4f5576329d82b2 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 19 Oct 2018 02:44:08 +0800 Subject: [PATCH] Allow dynamic parameter to be returned even if path matches nothing (#7957) --- .../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 dc4d1f3365..6e845601d5 100644 --- a/src/System.Management.Automation/engine/SessionStateContent.cs +++ b/src/System.Management.Automation/engine/SessionStateContent.cs @@ -275,13 +275,7 @@ namespace System.Management.Automation 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 aa1650e071..eac53dd780 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"