Skip to content

Commit

Permalink
(AB-168933) Clarify Length and Count for PSCustomObject
Browse files Browse the repository at this point in the history
Prior to this change, the documentation note for the **Length**
and **Count** properties of **PSCustomObjects** created by
casting a hashtable indicated that, for Windows PowerShell,
those properties don't exist on the object and accessing them
returns `$null`.

However, in PowerShell, those members exist and return a value
of `1`.

This change:

- Updates the note to indicate the changed behavior.
- Fixes AB#168933
  • Loading branch information
michaeltlombardi committed Oct 11, 2023
1 parent 861ae1e commit 2650605
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains the differences between the [psobject] and [pscustomobject] type accelerators.
Locale: en-US
ms.date: 12/05/2022
ms.date: 10/11/2023
online version: https://learn.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
Expand Down Expand Up @@ -219,7 +219,7 @@ have subtle side effects.
## Notes

In Windows PowerShell, objects created by casting a **Hashtable** to
`[pscustomobject]` do not have the **Length** or **Count** properties.
`[pscustomobject]` don't have the **Length** or **Count** properties.
Attempting to access these members returns `$null`.

For example:
Expand All @@ -236,6 +236,10 @@ PS> $object.Count
PS> $object.Length
```

Starting in PowerShell 6, objects created by casting a **Hashtable** to
`[pscustomobject]` always have a value of `1` for the **Length** and **Count**
properties.

## See also

- [about_Object_Creation][01]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains the differences between the [psobject] and [pscustomobject] type accelerators.
Locale: en-US
ms.date: 12/05/2022
ms.date: 10/11/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSCustomObject?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSCustomObject
Expand Down Expand Up @@ -214,7 +214,7 @@ have subtle side effects.
## Notes

In Windows PowerShell, objects created by casting a **Hashtable** to
`[pscustomobject]` do not have the **Length** or **Count** properties.
`[pscustomobject]` don't have the **Length** or **Count** properties.
Attempting to access these members returns `$null`.

For example:
Expand All @@ -231,6 +231,10 @@ PS> $object.Count
PS> $object.Length
```

Starting in PowerShell 6, objects created by casting a **Hashtable** to
`[pscustomobject]` always have a value of `1` for the **Length** and **Count**
properties.

## See also

- [about_Object_Creation][01]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains the differences between the [psobject] and [pscustomobject] type accelerators.
Locale: en-US
ms.date: 12/05/2022
ms.date: 10/11/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_pscustomobject?view=powershell-7.3&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSCustomObject
Expand Down Expand Up @@ -214,7 +214,7 @@ have subtle side effects.
## Notes

In Windows PowerShell, objects created by casting a **Hashtable** to
`[pscustomobject]` do not have the **Length** or **Count** properties.
`[pscustomobject]` don't have the **Length** or **Count** properties.
Attempting to access these members returns `$null`.

For example:
Expand All @@ -231,6 +231,10 @@ PS> $object.Count
PS> $object.Length
```

Starting in PowerShell 6, objects created by casting a **Hashtable** to
`[pscustomobject]` always have a value of `1` for the **Length** and **Count**
properties.

## See also

- [about_Object_Creation][01]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains the differences between the [psobject] and [pscustomobject] type accelerators.
Locale: en-US
ms.date: 12/05/2022
ms.date: 10/11/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_pscustomobject?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSCustomObject
Expand Down Expand Up @@ -214,7 +214,7 @@ have subtle side effects.
## Notes

In Windows PowerShell, objects created by casting a **Hashtable** to
`[pscustomobject]` do not have the **Length** or **Count** properties.
`[pscustomobject]` don't have the **Length** or **Count** properties.
Attempting to access these members returns `$null`.

For example:
Expand All @@ -231,6 +231,10 @@ PS> $object.Count
PS> $object.Length
```

Starting in PowerShell 6, objects created by casting a **Hashtable** to
`[pscustomobject]` always have a value of `1` for the **Length** and **Count**
properties.

## See also

- [about_Object_Creation][01]
Expand Down

0 comments on commit 2650605

Please sign in to comment.