I'm attempting to send a MessageCard
to Microsoft Teams and in doing so I need to construct JSON out of many variables. My issue is that a nested array inside my hashtable shows up with the object's type
rather than it's value
:
PowerShell:
$jsonHash = [ordered]@{
'@type' = "MessageCard"
'@context' = "https://schema.org/extensions"
'summary' = $SummaryText
'themeColor' = $ThemeColor
'title' = $Title
'sections' = @(
[ordered]@{
'activityTitle' = $ActivityTitle
'activitySubTitle' = $ActivitySubTitle
'activityImage' = $ActivityImageUrl
'text' = $BodyText
'facts' = @(
[ordered]@{
'name' = 'Computer'
'value' = $env:COMPUTERNAME
},
[ordered]@{
'name' = 'IP Address'
'value' = $((Get-NetIPConfiguration | Where-Object {$_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -ne "Disconnected"}).IPv4Address.IPAddress)
}
)
}
)
'potentialAction' = @(
[ordered]@{
'@type' = 'HttpPOST'
'name' = 'Activate'
'target' = $targetUrl
}
)
}
return $jsonHash | ConvertTo-Json
The output of this shows the facts
tag as System.Collections.Specialized.OrderedDirectionary
and not the correct JSON output I would expect:
JSON Output:
{
"@type": "MessageCard",
"@context": "https://schema.org/extensions",
"summary": "Node Activation for TESTPC",
"themeColor": "0078D7",
"title": null,
"sections": [
{
"activityTitle": "Network Node TESTPC requesting activation",
"activitySubTitle": null,
"activityImage": "<removed>",
"text": "Some text here",
"facts": "System.Collections.Specialized.OrderedDictionary System.Collections.Specialized.OrderedDictionary"
}
],
"potentialAction": [
{
"@type": "HttpPOST",
"name": "Activate",
"header": "System.Collections.Hashtable",
"target": "<removed>"
}
]
}
Even the header
value shows up as System.Collections.Hashtable
instead of the correct value.
Any ideas on how I can get the JSON formatted correctly with this complex object?