From dc1d672a865d35641d11c53f6cc5ec167fb8847c Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Thu, 30 Jun 2016 18:16:37 -0700 Subject: [PATCH] Fix Measure-Object -Property w/ wildcards Fixes #1215 --- .../commands/utility/Measure-Object.cs | 2 +- .../Measure-Object.Tests.ps1 | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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 015c7a4e8..7bc100225 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 69f804895..e85abdf60 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 +}