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 26540f05856..9befe0c608e 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs
@@ -310,6 +310,26 @@ public SwitchParameter Sum
}
private bool _measureSum;
+ ///
+ /// Gets or sets the value indicating if all statistics should be returned.
+ ///
+ ///
+ [Parameter(ParameterSetName = GenericParameterSet)]
+ public SwitchParameter AllStats
+ {
+ get
+ {
+ return _allStats;
+ }
+
+ set
+ {
+ _allStats = value;
+ }
+ }
+
+ private bool _allStats;
+
///
/// Set to true is Average is to be returned
///
@@ -451,6 +471,21 @@ private bool IsMeasuringGeneric
}
}
+ ///
+ /// Does the begin part of the cmdlet.
+ ///
+ protected override void BeginProcessing()
+ {
+ // Sets all other generic parameters to true to get all statistics.
+ if (_allStats)
+ {
+ _measureSum = _measureStandardDeviation = _measureAverage = _measureMax = _measureMin = true;
+ }
+
+ // finally call the base class.
+ base.BeginProcessing();
+ }
+
///
/// Collect data about each record that comes in.
/// Side effects: Updates totalRecordCount.
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 b0155a79344..6c24ec0dcb5 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1
@@ -174,6 +174,16 @@ Describe "Measure-Object" -Tags "CI" {
$actual.Maximum | Should -Be $expected
}
+
+ It "Should be able to return all the statitics for given values" {
+ $result = 1..10 | Measure-Object -AllStats
+ $result.Count | Should -Be 10
+ $result.Average | Should -Be 5.5
+ $result.Sum | Should -Be 55
+ $result.Minimum | Should -Be 1
+ $result.Maximum | Should -Be 10
+ ($result.StandardDeviation).ToString() | Should -Be '3.02765035409749'
+ }
}
Context "String tests" {