From 1367f1f991d1f96aef7b0a58d6b65f0923106e5f Mon Sep 17 00:00:00 2001 From: freddydk Date: Thu, 4 Aug 2022 09:59:22 +0200 Subject: [PATCH] add recurse to ConvertTo-HashTable --- Misc/ConvertTo-HashTable.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Misc/ConvertTo-HashTable.ps1 b/Misc/ConvertTo-HashTable.ps1 index dcbdc2200..696f57feb 100644 --- a/Misc/ConvertTo-HashTable.ps1 +++ b/Misc/ConvertTo-HashTable.ps1 @@ -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 }