From 30c85a3e34184218f9931d0b04af06506c9f36d8 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Tue, 3 Sep 2024 14:06:44 -0500 Subject: [PATCH] Improve description of Measure-Object example --- .../About/about_Calculated_Properties.md | 51 ++++++++++------ .../About/about_Calculated_Properties.md | 59 ++++++++++++------- .../About/about_Calculated_Properties.md | 59 ++++++++++++------- .../About/about_Calculated_Properties.md | 59 ++++++++++++------- 4 files changed, 150 insertions(+), 78 deletions(-) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index 301d3385fe4c..6c5295e39acd 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -1,7 +1,7 @@ --- description: PowerShell provides the ability to dynamically add new properties and alter the formatting of objects output to the pipeline. Locale: en-US -ms.date: 03/24/2023 +ms.date: 09/03/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_calculated_properties?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Calculated Properties @@ -19,9 +19,9 @@ Several PowerShell cmdlets transform, group, or process input objects into output objects using parameters that allow the addition of new properties to those output objects. You can use these parameters to generate new, calculated properties on output objects based on the values of input objects. The -calculated property is defined by a [hashtable](about_hash_tables.md) -containing key-value pairs that specify the name of the new property, an -expression to calculate the value, and optional formatting information. +calculated property is defined by a [hashtable][03] containing key-value pairs +that specify the name of the new property, an expression to calculate the +value, and optional formatting information. ## Supported cmdlets @@ -81,7 +81,7 @@ the key-value pairs that each cmdlet supports. > [!NOTE] > The value of the `expression` can be a script block instead of a -> hashtable. For more information, see the [Notes](#notes) section. +> hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions @@ -96,7 +96,7 @@ the key-value pairs that each cmdlet supports. `'right'`. - `formatstring` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see - [Format types in .NET](/dotnet/standard/base-types/formatting-types). + [Format types in .NET][01]. - `width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. - `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of @@ -473,15 +473,30 @@ Date Salesperson UnitsSold ## See also -- [about_Hash_Tables](about_hash_tables.md) -- [ConvertTo-Html](xref:Microsoft.PowerShell.Utility.ConvertTo-Html) -- [Format-Custom](xref:Microsoft.PowerShell.Utility.Format-Custom) -- [Format-List](xref:Microsoft.PowerShell.Utility.Format-List) -- [Format-Table](xref:Microsoft.PowerShell.Utility.Format-Table) -- [Format-Wide](xref:Microsoft.PowerShell.Utility.Format-Wide) -- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) -- [Group-Object](xref:Microsoft.PowerShell.Utility.Group-Object) -- [Measure-Object](xref:Microsoft.PowerShell.Utility.Measure-Object) -- [Select-Object](xref:Microsoft.PowerShell.Utility.Select-Object) -- [Sort-Object](xref:Microsoft.PowerShell.Utility.Sort-Object) -- [Format types in .NET](/dotnet/standard/base-types/formatting-types) +- [about_Hash_Tables][03] +- [ConvertTo-Html][05] +- [Format-Custom][06] +- [Format-List][07] +- [Format-Table][08] +- [Format-Wide][09] +- [Compare-Object][04] +- [Group-Object][10] +- [Measure-Object][11] +- [Select-Object][12] +- [Sort-Object][13] +- [Format types in .NET][01] + + +[01]: /dotnet/standard/base-types/formatting-types +[02]: #notes +[03]: about_hash_tables.md +[04]: xref:Microsoft.PowerShell.Utility.Compare-Object +[05]: xref:Microsoft.PowerShell.Utility.ConvertTo-Html +[06]: xref:Microsoft.PowerShell.Utility.Format-Custom +[07]: xref:Microsoft.PowerShell.Utility.Format-List +[08]: xref:Microsoft.PowerShell.Utility.Format-Table +[09]: xref:Microsoft.PowerShell.Utility.Format-Wide +[10]: xref:Microsoft.PowerShell.Utility.Group-Object +[11]: xref:Microsoft.PowerShell.Utility.Measure-Object +[12]: xref:Microsoft.PowerShell.Utility.Select-Object +[13]: xref:Microsoft.PowerShell.Utility.Sort-Object diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index 775766d71131..49ca9bc547b2 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -1,7 +1,7 @@ --- description: PowerShell provides the ability to dynamically add new properties and alter the formatting of objects output to the pipeline. Locale: en-US -ms.date: 03/24/2023 +ms.date: 09/03/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_calculated_properties?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Calculated Properties @@ -19,9 +19,9 @@ Several PowerShell cmdlets transform, group, or process input objects into output objects using parameters that allow the addition of new properties to those output objects. You can use these parameters to generate new, calculated properties on output objects based on the values of input objects. The -calculated property is defined by a [hashtable](about_hash_tables.md) -containing key-value pairs that specify the name of the new property, an -expression to calculate the value, and optional formatting information. +calculated property is defined by a [hashtable][03] containing key-value pairs +that specify the name of the new property, an expression to calculate the +value, and optional formatting information. ## Supported cmdlets @@ -81,7 +81,7 @@ the key-value pairs that each cmdlet supports. > [!NOTE] > The value of the `expression` can be a script block instead of a -> hashtable. For more information, see the [Notes](#notes) section. +> hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions @@ -96,7 +96,7 @@ the key-value pairs that each cmdlet supports. `'right'`. - `formatstring` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see - [Format types in .NET](/dotnet/standard/base-types/formatting-types). + [Format types in .NET][01]. - `width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. - `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of @@ -361,8 +361,12 @@ Count Name ### Measure-Object The `Measure-Object` cmdlet calculates the numeric properties of objects. In -this example, we use a calculated property to get the count (**Sum**) of the -numbers, between 1 and 10, that are evenly divisible by 3. +this example, we use a calculated property to get the count of the numbers +between 1 and 10 that are evenly divisible by 3. + +The script block returns `$true` if the number is divisible by 3 and `$false` +for all other numbers. The **Sum** operation treats `$true` values as `1` and +`$false` values as `0`. ```powershell 1..10 | Measure-Object -Property {($_ % 3) -eq 0} -Sum @@ -498,15 +502,30 @@ Date Salesperson UnitsSold ## See also -- [about_Hash_Tables](about_hash_tables.md) -- [ConvertTo-Html](xref:Microsoft.PowerShell.Utility.ConvertTo-Html) -- [Format-Custom](xref:Microsoft.PowerShell.Utility.Format-Custom) -- [Format-List](xref:Microsoft.PowerShell.Utility.Format-List) -- [Format-Table](xref:Microsoft.PowerShell.Utility.Format-Table) -- [Format-Wide](xref:Microsoft.PowerShell.Utility.Format-Wide) -- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) -- [Group-Object](xref:Microsoft.PowerShell.Utility.Group-Object) -- [Measure-Object](xref:Microsoft.PowerShell.Utility.Measure-Object) -- [Select-Object](xref:Microsoft.PowerShell.Utility.Select-Object) -- [Sort-Object](xref:Microsoft.PowerShell.Utility.Sort-Object) -- [Format types in .NET](/dotnet/standard/base-types/formatting-types) +- [about_Hash_Tables][03] +- [ConvertTo-Html][05] +- [Format-Custom][06] +- [Format-List][07] +- [Format-Table][08] +- [Format-Wide][09] +- [Compare-Object][04] +- [Group-Object][10] +- [Measure-Object][11] +- [Select-Object][12] +- [Sort-Object][13] +- [Format types in .NET][01] + + +[01]: /dotnet/standard/base-types/formatting-types +[02]: #notes +[03]: about_hash_tables.md +[04]: xref:Microsoft.PowerShell.Utility.Compare-Object +[05]: xref:Microsoft.PowerShell.Utility.ConvertTo-Html +[06]: xref:Microsoft.PowerShell.Utility.Format-Custom +[07]: xref:Microsoft.PowerShell.Utility.Format-List +[08]: xref:Microsoft.PowerShell.Utility.Format-Table +[09]: xref:Microsoft.PowerShell.Utility.Format-Wide +[10]: xref:Microsoft.PowerShell.Utility.Group-Object +[11]: xref:Microsoft.PowerShell.Utility.Measure-Object +[12]: xref:Microsoft.PowerShell.Utility.Select-Object +[13]: xref:Microsoft.PowerShell.Utility.Sort-Object diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index 77a855818e42..51d92930b376 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -1,7 +1,7 @@ --- description: PowerShell provides the ability to dynamically add new properties and alter the formatting of objects output to the pipeline. Locale: en-US -ms.date: 03/24/2023 +ms.date: 09/03/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_calculated_properties?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Calculated Properties @@ -19,9 +19,9 @@ Several PowerShell cmdlets transform, group, or process input objects into output objects using parameters that allow the addition of new properties to those output objects. You can use these parameters to generate new, calculated properties on output objects based on the values of input objects. The -calculated property is defined by a [hashtable](about_hash_tables.md) -containing key-value pairs that specify the name of the new property, an -expression to calculate the value, and optional formatting information. +calculated property is defined by a [hashtable][03] containing key-value pairs +that specify the name of the new property, an expression to calculate the +value, and optional formatting information. ## Supported cmdlets @@ -81,7 +81,7 @@ the key-value pairs that each cmdlet supports. > [!NOTE] > The value of the `expression` can be a script block instead of a -> hashtable. For more information, see the [Notes](#notes) section. +> hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions @@ -96,7 +96,7 @@ the key-value pairs that each cmdlet supports. `'right'`. - `formatstring` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see - [Format types in .NET](/dotnet/standard/base-types/formatting-types). + [Format types in .NET][01]. - `width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. - `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of @@ -361,8 +361,12 @@ Count Name ### Measure-Object The `Measure-Object` cmdlet calculates the numeric properties of objects. In -this example, we use a calculated property to get the count (**Sum**) of the -numbers, between 1 and 10, that are evenly divisible by 3. +this example, we use a calculated property to get the count of the numbers +between 1 and 10 that are evenly divisible by 3. + +The script block returns `$true` if the number is divisible by 3 and `$false` +for all other numbers. The **Sum** operation treats `$true` values as `1` and +`$false` values as `0`. ```powershell 1..10 | Measure-Object -Property {($_ % 3) -eq 0} -Sum @@ -498,15 +502,30 @@ Date Salesperson UnitsSold ## See also -- [about_Hash_Tables](about_hash_tables.md) -- [ConvertTo-Html](xref:Microsoft.PowerShell.Utility.ConvertTo-Html) -- [Format-Custom](xref:Microsoft.PowerShell.Utility.Format-Custom) -- [Format-List](xref:Microsoft.PowerShell.Utility.Format-List) -- [Format-Table](xref:Microsoft.PowerShell.Utility.Format-Table) -- [Format-Wide](xref:Microsoft.PowerShell.Utility.Format-Wide) -- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) -- [Group-Object](xref:Microsoft.PowerShell.Utility.Group-Object) -- [Measure-Object](xref:Microsoft.PowerShell.Utility.Measure-Object) -- [Select-Object](xref:Microsoft.PowerShell.Utility.Select-Object) -- [Sort-Object](xref:Microsoft.PowerShell.Utility.Sort-Object) -- [Format types in .NET](/dotnet/standard/base-types/formatting-types) +- [about_Hash_Tables][03] +- [ConvertTo-Html][05] +- [Format-Custom][06] +- [Format-List][07] +- [Format-Table][08] +- [Format-Wide][09] +- [Compare-Object][04] +- [Group-Object][10] +- [Measure-Object][11] +- [Select-Object][12] +- [Sort-Object][13] +- [Format types in .NET][01] + + +[01]: /dotnet/standard/base-types/formatting-types +[02]: #notes +[03]: about_hash_tables.md +[04]: xref:Microsoft.PowerShell.Utility.Compare-Object +[05]: xref:Microsoft.PowerShell.Utility.ConvertTo-Html +[06]: xref:Microsoft.PowerShell.Utility.Format-Custom +[07]: xref:Microsoft.PowerShell.Utility.Format-List +[08]: xref:Microsoft.PowerShell.Utility.Format-Table +[09]: xref:Microsoft.PowerShell.Utility.Format-Wide +[10]: xref:Microsoft.PowerShell.Utility.Group-Object +[11]: xref:Microsoft.PowerShell.Utility.Measure-Object +[12]: xref:Microsoft.PowerShell.Utility.Select-Object +[13]: xref:Microsoft.PowerShell.Utility.Sort-Object diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index aa12277ffee9..00b7df7f8f15 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -1,7 +1,7 @@ --- description: PowerShell provides the ability to dynamically add new properties and alter the formatting of objects output to the pipeline. Locale: en-US -ms.date: 03/24/2023 +ms.date: 09/03/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_calculated_properties?view=powershell-7.5&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Calculated Properties @@ -19,9 +19,9 @@ Several PowerShell cmdlets transform, group, or process input objects into output objects using parameters that allow the addition of new properties to those output objects. You can use these parameters to generate new, calculated properties on output objects based on the values of input objects. The -calculated property is defined by a [hashtable](about_hash_tables.md) -containing key-value pairs that specify the name of the new property, an -expression to calculate the value, and optional formatting information. +calculated property is defined by a [hashtable][03] containing key-value pairs +that specify the name of the new property, an expression to calculate the +value, and optional formatting information. ## Supported cmdlets @@ -81,7 +81,7 @@ the key-value pairs that each cmdlet supports. > [!NOTE] > The value of the `expression` can be a script block instead of a -> hashtable. For more information, see the [Notes](#notes) section. +> hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions @@ -96,7 +96,7 @@ the key-value pairs that each cmdlet supports. `'right'`. - `formatstring` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see - [Format types in .NET](/dotnet/standard/base-types/formatting-types). + [Format types in .NET][01]. - `width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. - `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of @@ -361,8 +361,12 @@ Count Name ### Measure-Object The `Measure-Object` cmdlet calculates the numeric properties of objects. In -this example, we use a calculated property to get the count (**Sum**) of the -numbers, between 1 and 10, that are evenly divisible by 3. +this example, we use a calculated property to get the count of the numbers +between 1 and 10 that are evenly divisible by 3. + +The script block returns `$true` if the number is divisible by 3 and `$false` +for all other numbers. The **Sum** operation treats `$true` values as `1` and +`$false` values as `0`. ```powershell 1..10 | Measure-Object -Property {($_ % 3) -eq 0} -Sum @@ -498,15 +502,30 @@ Date Salesperson UnitsSold ## See also -- [about_Hash_Tables](about_hash_tables.md) -- [ConvertTo-Html](xref:Microsoft.PowerShell.Utility.ConvertTo-Html) -- [Format-Custom](xref:Microsoft.PowerShell.Utility.Format-Custom) -- [Format-List](xref:Microsoft.PowerShell.Utility.Format-List) -- [Format-Table](xref:Microsoft.PowerShell.Utility.Format-Table) -- [Format-Wide](xref:Microsoft.PowerShell.Utility.Format-Wide) -- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) -- [Group-Object](xref:Microsoft.PowerShell.Utility.Group-Object) -- [Measure-Object](xref:Microsoft.PowerShell.Utility.Measure-Object) -- [Select-Object](xref:Microsoft.PowerShell.Utility.Select-Object) -- [Sort-Object](xref:Microsoft.PowerShell.Utility.Sort-Object) -- [Format types in .NET](/dotnet/standard/base-types/formatting-types) +- [about_Hash_Tables][03] +- [ConvertTo-Html][05] +- [Format-Custom][06] +- [Format-List][07] +- [Format-Table][08] +- [Format-Wide][09] +- [Compare-Object][04] +- [Group-Object][10] +- [Measure-Object][11] +- [Select-Object][12] +- [Sort-Object][13] +- [Format types in .NET][01] + + +[01]: /dotnet/standard/base-types/formatting-types +[02]: #notes +[03]: about_hash_tables.md +[04]: xref:Microsoft.PowerShell.Utility.Compare-Object +[05]: xref:Microsoft.PowerShell.Utility.ConvertTo-Html +[06]: xref:Microsoft.PowerShell.Utility.Format-Custom +[07]: xref:Microsoft.PowerShell.Utility.Format-List +[08]: xref:Microsoft.PowerShell.Utility.Format-Table +[09]: xref:Microsoft.PowerShell.Utility.Format-Wide +[10]: xref:Microsoft.PowerShell.Utility.Group-Object +[11]: xref:Microsoft.PowerShell.Utility.Measure-Object +[12]: xref:Microsoft.PowerShell.Utility.Select-Object +[13]: xref:Microsoft.PowerShell.Utility.Sort-Object