-
Notifications
You must be signed in to change notification settings - Fork 28
/
New-FlatObject.ps1
31 lines (30 loc) · 1.2 KB
/
New-FlatObject.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function New-FlatObject {
Param
(
[Parameter(Mandatory, ValueFromPipeline)]
$object
)
process {
$returnHashTable = [ordered]@{ }
foreach ($prop in $object.psobject.Properties) {
if ($prop.Value -is [array]) {
#if (($prop.Value -ne $null) -and (-not $prop.Value.GetType().isValueType))
$counter = 0
foreach ($value in $prop.Value) {
if ($value -is [array]) {
#if (($prop.Value -ne $null) -and (-not $prop.Value.GetType().isValueType))
foreach ($recurse in (New-FlatObject -object $value).psobject.Properties) {
$returnHashTable["$($prop.Name)-$($recurse.Name)"] = $recurse.Value
}
}
$returnHashTable["$($prop.Name)-$counter"] = $value
$counter++
}
}
else {
$returnHashTable[$prop.Name] = $prop.Value
}
}
return [PSCustomObject]$returnHashTable | Sort-Object @{Expression = { (($_.psobject.properties) | Measure-Object).count } } -Descending
}
}