diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs index 015c7a4e8f..7bc1002252 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs @@ -548,7 +548,7 @@ namespace Microsoft.PowerShell.Commands // properties... foreach (string p in Property) { - MshExpression expression = new MshExpression(p, true); + MshExpression expression = new MshExpression(p); List resolvedNames = expression.ResolveNames(inObj); if (resolvedNames == null || resolvedNames.Count == 0) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 index 69f8048951..e85abdf605 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1 @@ -20,6 +20,22 @@ Describe "Measure-Object" { $actual | Should Be $expected } + It "Should be able to use wildcards for the Property argument" { + $data = [pscustomobject]@{ A1 = 1; A2 = 2; C3 = 3 }, + [pscustomobject]@{ A1 = 1; A2 = 2; A3 = 3 } + $actual = $data | Measure-Object -Property A* -Sum + $actual.Count | Should Be 3 + $actual[0].Property | Should Be A1 + $actual[0].Sum | Should Be 2 + $actual[0].Count | Should Be 2 + $actual[1].Property | Should Be A2 + $actual[1].Sum | Should Be 4 + $actual[1].Count | Should Be 2 + $actual[2].Property | Should Be A3 + $actual[2].Sum | Should Be 3 + $actual[2].Count | Should Be 1 + } + Context "Numeric tests" { It "Should be able to sum" { $actual = $testObject | Measure-Object -Sum @@ -289,4 +305,4 @@ Describe "Measure-Object DRT basic functionality" -Tags DRT{ $result = "123`n4"|measure-object -line $result.Lines | Should Be 2 } -} \ No newline at end of file +}