diff --git a/src/System.Management.Automation/engine/SessionStateContainer.cs b/src/System.Management.Automation/engine/SessionStateContainer.cs index d84af11f99..3485c3f493 100644 --- a/src/System.Management.Automation/engine/SessionStateContainer.cs +++ b/src/System.Management.Automation/engine/SessionStateContainer.cs @@ -1654,7 +1654,25 @@ namespace System.Management.Automation ContainerCmdletProvider providerInstance = GetContainerProviderInstance(provider); - if (path != null && this.ItemExists(providerInstance, path, context)) + if ( + (context.Include != null && context.Include.Count > 0) || + (context.Exclude != null && context.Exclude.Count > 0)) + { + // Do the recursion manually so that we can apply the + // include and exclude filters + int unUsedChildrenNotMatchingFilterCriteria = 0; + try + { + // Temeporary set literal path as false to apply filter + context.SuppressWildcardExpansion = false; + ProcessPathItems(providerInstance, path, recurse, depth, context, out unUsedChildrenNotMatchingFilterCriteria, ProcessMode.Enumerate); + } + finally + { + context.SuppressWildcardExpansion = true; + } + } + else if (path != null && this.ItemExists(providerInstance, path, context)) { if (IsItemContainer(providerInstance, path, context)) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 index 8b061fa034..4486f7c698 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 @@ -95,6 +95,13 @@ Describe "Get-ChildItem" -Tags "CI" { (Get-ChildItem -Path $TestDrive -Depth 1 -Exclude $item_a).Count | Should Be 5 } + It "Should return items recursively when using 'Include' or 'Exclude' parameters with -LiteralPath" { + (Get-ChildItem -LiteralPath $TestDrive -Recurse -Exclude *).Count | Should Be 0 + (Get-ChildItem -LiteralPath $TestDrive -Recurse -Include *.dll).Count | Should Be (Get-ChildItem $TestDrive -Recurse -Include *.dll).Count + (Get-ChildItem -LiteralPath $TestDrive -Depth 1 -Include $item_G).Count | Should Be 1 + (Get-ChildItem -LiteralPath $TestDrive -Depth 1 -Exclude $item_a).Count | Should Be 5 + } + It "get-childitem path wildcard - " -TestCases $PathWildCardTestCases { param($Parameters, $ExpectedCount)