0

I am using additionalProperties in swagger because of which I am getting the output in the below format in powershell:

Path:         ABC
Keys:         {KeyX, KeyY}
Values:       {ValueOfX, ValueOfY}
Count:        2
...   

Is there any way that this can be displayed as:

Path:         ABC
KeyX:         ValueOfX
KeyY:         ValueOfY

For expanding the additional properties this is what has been used:

$Properties = $obj | Select-Object -ExpandProperty AdditionalProperties
Saniaaa
  • 35
  • 4

1 Answers1

0

Create an [ordered] dictionary to hold the property entries, populate it by correlating the Keys and Values items by index, and then convert the dictionary to an object:

# Create dictionary, add `Path` property entry
$newObjectProperties = [ordered]@{
  Path = $additionalProperties.Path
}

# Correlate Key-Value pairs by index, add to dictionary
for($i = 0; $i -lt $additionalProperties.Count; $i++){
  $newObjectProperties[$additionalProperties.Keys[$i]] = $additionalProperties.Values[$i]
}

# Convert dictionary to an object
$finalObject = [PSCustomObject]$newObjectProperties
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206