Service | Microsoft Docs article | Related commit history on GitHub | Change details |
---|---|---|---|
Microsoft.PowerShell.Core | About Arrays (5.1) | https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Arrays.md | faster, especially for large arrays. ## Arrays of zero or one -Beginning in Windows PowerShell 3.0, a collection of zero or one object has -the Count and Length property. Also, you can index into an array of one +Beginning in Windows PowerShell 3.0, a collection of zero or one object has the +**Count** and **Length** properties. Also, you can index into an array of one object. This feature helps you to avoid scripting errors that occur when a command that expects a collection gets fewer than two items. +> [!NOTE] +In Windows PowerShell, objects created by casting a **Hashtable** to +`[pscustomobject]` do not have the **Length** or **Count** properties. +Attempting to access these members returns `$null`. + The following examples demonstrate this feature. ### Zero objects |
Microsoft.PowerShell.Core | About Pscustomobject (5.1) | https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_PSCustomObject.md | --- description: Explains the differences between PSObject and PSCustomObject. Locale: en-US Previously updated : 08/10/2021 Last updated : 03/08/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_pscustomobject?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about PSCustomObject PS> ([PSCustomObject]@{Property = 'Value'}).GetType().FullName System.Management.Automation.PSCustomObject ``` +## Notes ++In Windows PowerShell, objects created by casting a **Hashtable** to +`[pscustomobject]` do not have the **Length** or **Count** properties. +Attempting to access these members returns `$null`. ++For example: ++```powershell +PS> $object = [PSCustomObject]@{key = 'value'} +PS> $object ++key +--- +value ++PS> $object.Count +PS> $object.Length +``` + ## See also - [about_Object_Creation](about_Object_Creation.md) |
Microsoft.PowerShell.Utility | Measure Object (7.3) | https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.3/Microsoft.PowerShell.Utility/Measure-Object.md | external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 07/15/2021 Last updated : 03/08/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/measure-object?view=powershell-7.3&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Measure-Object Otherwise, it returns a **GenericMeasureInfo** object. ## NOTES +Starting in PowerShell 7.3, `Measure-Object` no longer returns an error when +processing an object that is missing the property being measured unless you are +running in **StrictMode**. In **StrictMode**, `Measure-Object` returns a +`System.Management.Automation.PSArgumentException` when processing an object +that is missing the specified property. + ## RELATED LINKS [about_Calculated_Properties](../Microsoft.PowerShell.Core/About/about_Calculated_Properties.md) |