Skip to content

Commit ab70545

Browse files
authored
Merge pull request #2632 from microsoft/dev
add recurse to ConvertTo-HashTable
2 parents 8823a41 + 1367f1f commit ab70545

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Misc/ConvertTo-HashTable.ps1

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ function ConvertTo-HashTable() {
1010
[CmdletBinding()]
1111
Param(
1212
[parameter(ValueFromPipeline)]
13-
[PSCustomObject] $object
13+
[PSCustomObject] $object,
14+
[switch] $recurse
1415
)
1516
$ht = @{}
1617
if ($object) {
17-
$object.PSObject.Properties | Foreach { $ht[$_.Name] = $_.Value }
18+
$object.PSObject.Properties | ForEach-Object {
19+
if ($recurse -and ($_.Value -is [PSCustomObject])) {
20+
$ht[$_.Name] = ConvertTo-HashTable $_.Value
21+
}
22+
else {
23+
$ht[$_.Name] = $_.Value
24+
}
25+
}
1826
}
1927
$ht
2028
}

0 commit comments

Comments
 (0)