Teams Webhook错误:Invoke-RestMethod:泛型传入Webhook接收到错误的负载



我在Powershell脚本中使用已配置的Teams webhook,并不断遇到上述错误消息。奇怪的是,这种配置Webhook的确切方法几个月前在另一个脚本上运行。

以下是我要做的:

#Set URI of the Teams channel Webhook
$URI = 'https:....'
#Define Rest Method Parameters for the Teams Webhook sending
$RestMethodParameters = @{
"URI"         = $URI
"Method"      = 'POST'
"Body"        = $null
"ContentType" = 'application/json'
}
$JSONBody = @{
"@type"      = "MessageCard"
"@context"   = "http://schema.org/extensions"
"themeColor" = '0078D7'
}
#Adding text to title and body
$JSONBody += @{
"title" = "'costReport-func' Function for connecting AzAccount has failed"
"text"  = "Function failed at connection to AzAccount step."
}
#Sending the message to Teams
($RestMethodParameters).Body += ConvertTo-Json $JSONBody
Invoke-RestMethod @RestMethodParameters

有了这个,我得到了";一般传入的webhook接收到错误的负载"错误消息。是什么导致了这里的问题?

更新:微软发布了Teams PowerShell模块的预览版(2.1.0(,该模块可与现代身份验证一起正常工作。这个版本很可能会很快推出。请通过此链接了解更多信息。

最新更新