Internal/Generic/Convert-PSObjectToHashtable.ps1
#Requires -Version 5.0 function Convert-PSObjectToHashtable { param ( [Parameter( Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [object]$InputObject ) if (-not $InputObject) { return $null } if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string]) { $output = @( foreach ($item in $InputObject) { Convert-PSObjectToHashtable $item } ) Write-Output -NoEnumerate $output } elseif ($InputObject -is [psobject]) { $output = @{} $InputObject | Get-Member -MemberType *Property | % { $output.($_.name) = Convert-PSObjectToHashtable $InputObject.($_.name) } $output } else { $InputObject } } |