Powershell 团队Webhook错误:调用RestMethod:通用传入Webhook接收到错误的负载

Powershell 团队Webhook错误:调用RestMethod:通用传入Webhook接收到错误的负载,powershell,webhooks,microsoft-teams,Powershell,Webhooks,Microsoft Teams,我在Powershell脚本中使用已配置的Teams webhook,并不断遇到提到的错误消息。奇怪的是,这个配置Webhook的方法几个月前在另一个脚本上运行 以下是我想做的: #Set URI of the Teams channel Webhook $URI = 'https:....' #Define Rest Method Parameters for the Teams Webhook sending $RestMethodParameters = @{ "URI

我在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接收到的无效负载”错误消息。是什么导致了此问题?

更新:Microsoft发布了Teams PowerShell模块的预览版(2.1.0),可与现代身份验证一起正常工作。这个版本很可能会很快推出。
有关详细信息,请仔细阅读。

尝试跳过对
converttojson
的显式调用,只需按原样将
$JSONBody
直接分配给
$RestMethodParameters.Body
,然后让
调用RestMethod
处理序列化iTunes的问题,在脚本中没有
converttojson
部分的情况下,我仍然收到相同的错误。