【发布时间】:2019-08-06 16:05:48
【问题描述】:
我正在尝试编写一个 PowerShell 函数来调用 Slack webhook。我从Reddit post 中获取了该函数,但该函数似乎因解析错误而失败。我还删除了 webhook。
代码如下:
function Send-SlackMessage {
Param (
[Parameter(Mandatory=$true, Position=0)]$Text,
$Url = "https://hooks.slack.com/services/xxxxx",
# Parameters below are optional and will fall back to the default
$Username = "XXXXXXX",
$Channel = "XXXXXXX",
$Emoji = "XXXXXX"
)
$body = @{ text=$Text; channel=$Channel; username=$Username; icon_emoji=$Emoji } | ConvertTo-Json
Invoke-WebRequest -Method Post -Uri $Url -Body $body
}
和错误:
在行:12 字符:67 + ... y = @{ 文本=$Text;频道=$频道;用户名=$用户名; icon_emoji=$ ... + 缺少 '=' @{ text=$Text;频道=$频道;用户名=$用户名; icon_emoji=$ ... 哈希文字不完整。 + CategoryInfo :ParserError (:) [], ParentContainsErrorRecordException + FillyQualifiedErrorId : MissingEqualsInHashLiteral【问题讨论】:
标签: powershell