From 49f87b737234581e11afea986c16d8a823e0f980 Mon Sep 17 00:00:00 2001 From: MrM40 Date: Sun, 20 Apr 2025 22:25:23 +0200 Subject: [PATCH] Update everything-about-pscustomobject.md Added how to get name or value by index-number. --- .../deep-dives/everything-about-pscustomobject.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/reference/docs-conceptual/learn/deep-dives/everything-about-pscustomobject.md b/reference/docs-conceptual/learn/deep-dives/everything-about-pscustomobject.md index dec633880aac..701b6af318b3 100644 --- a/reference/docs-conceptual/learn/deep-dives/everything-about-pscustomobject.md +++ b/reference/docs-conceptual/learn/deep-dives/everything-about-pscustomobject.md @@ -41,6 +41,13 @@ You can then access and use the values like you would a normal object. $myObject.Name ``` +To get name or value by index-number + +```powershell +$myObject.psobject.properties.Name[2] +$myObject.psobject.properts.Value[2] +``` + ### Converting a hashtable While I am on the topic, did you know you could do this: @@ -129,6 +136,13 @@ We can get this same list off of the `psobject` property too. $myobject.psobject.Properties.Name ``` +Or to get all values + +```powershell +$myobject.psobject.Properties.Value +``` + + > [!NOTE] > `Get-Member` returns the properties in alphabetical order. Using the member-access operator to > enumerate the property names returns the properties in the order they were defined on the object.