Skip to content

Commit

Permalink
Merge pull request #2632 from microsoft/dev
Browse files Browse the repository at this point in the history
add recurse to ConvertTo-HashTable
  • Loading branch information
freddydk authored Aug 4, 2022
2 parents 8823a41 + 1367f1f commit ab70545
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Misc/ConvertTo-HashTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ function ConvertTo-HashTable() {
[CmdletBinding()]
Param(
[parameter(ValueFromPipeline)]
[PSCustomObject] $object
[PSCustomObject] $object,
[switch] $recurse
)
$ht = @{}
if ($object) {
$object.PSObject.Properties | Foreach { $ht[$_.Name] = $_.Value }
$object.PSObject.Properties | ForEach-Object {
if ($recurse -and ($_.Value -is [PSCustomObject])) {
$ht[$_.Name] = ConvertTo-HashTable $_.Value
}
else {
$ht[$_.Name] = $_.Value
}
}
}
$ht
}
Expand Down

0 comments on commit ab70545

Please sign in to comment.