Get a node
Get-Node
-InputObject <Object>
[-Unique]
[-MaxDepth <Int32>]
[<CommonParameters>]
Get-Node
[-Path <Object>]
[-Literal]
[<CommonParameters>]
The Get-Node cmdlet gets the node at the specified property location of the supplied object graph.
The following example parses a hash table to [PSNode]
instance:
@{ 'My' = 1, 2, 3; 'Object' = 'Graph' } | Get-Node
PathName Name Depth Value
-------- ---- ----- -----
0 {My, Object}
The following example parses a hash table to [PSNode]
instance and selects the second (0
indexed)
item in the My
map node
@{ 'My' = 1, 2, 3; 'Object' = 'Graph' } | Get-Node My[1]
PathName Name Depth Value
-------- ---- ----- -----
My[1] 1 2 2
$ObjectGraph =
@{
BookStore = @(
@{
Book = @{
Title = 'Harry Potter'
Price = 29.99
}
},
@{
Book = @{
Title = 'Learning PowerShell'
Price = 39.95
}
}
)
}
($ObjectGraph | Get-Node BookStore~Title=*PowerShell*..Price).Value = 24.95
$ObjectGraph | ConvertTo-Expression
@{
BookStore = @(
@{
Book = @{
Price = 29.99
Title = 'Harry Potter'
}
},
@{
Book = @{
Price = 24.95
Title = 'Learning PowerShell'
}
}
)
}
for more details, see: PowerShell Object Parser and Extended dot notation
The concerned object graph or node.
Type: | Object |
Mandatory: | True |
Position: | Named |
Default value: | |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the path to a specific node in the object graph. The path might be either:
- A dot-notation (
[String]
) literal or expression (as natively used with PowerShell) - A array of strings (dictionary keys or Property names) and/or integers (list indices)
- A
[PSNodePath]
(such as$Node.Path
) or a[XdnPath]
(Extended Dot-Notation) object
Type: | Object |
Mandatory: | False |
Position: | Named |
Default value: | |
Accept pipeline input: | False |
Accept wildcard characters: | False |
If Literal switch is set, all (map) nodes in the given path are considered literal.
Type: | SwitchParameter |
Mandatory: | False |
Position: | Named |
Default value: | |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies that if a subset of the nodes has identical properties and values, only a single node of the subset should be selected.
Type: | SwitchParameter |
Mandatory: | False |
Position: | Named |
Default value: | |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the maximum depth that an object graph might be recursively iterated before it throws an error. The failsafe will prevent infinitive loops for circular references as e.g. in:
$Test = @{Guid = New-Guid}
$Test.Parent = $Test
The default MaxDepth
is defined by [PSNode]::DefaultMaxDepth = 10
.
Note
The MaxDepth
is bound to the root node of the object graph. Meaning that a descendant node
at depth of 3 can only recursively iterated (10 - 3 =
) 7
times.
Type: | Int32 |
Mandatory: | False |
Position: | Named |
Default value: | |
Accept pipeline input: | False |
Accept wildcard characters: | False |