I wanted a way to dynamically build output in Azure Automation for a database migration.
# Create the internal sections first with ElasticPoolName and databases joined with \n\n (new line in Teams)
$sections = $dbsPerElasticPool | ForEach-Object {
New-TeamsSection -ActivityTitle ('ElasticPool: **{0}**' -f $_.ElasticPool) -Value ($_.databases -join '\n\n')
}
# Create the rest of the card with the sections
$card = New-TeamsMessageCard -Sections $sections | ConvertTo-Json -Depth 5
# Required as ConvertTo-Json Escapes the newline strings 🤷♂️
$body = $card -replace '\\\\n\\\\n', '\n\n'
Invoke-RestMethod -Uri $webhookuri -Body $body -Method Post