Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell松弛函数_Powershell - Fatal编程技术网

PowerShell松弛函数

PowerShell松弛函数,powershell,Powershell,我正在尝试编写一个PowerShell函数来调用Slack webhook。我从中获取了函数,但该函数似乎由于解析错误而失败。我还删除了webhook 代码如下: function Send-SlackMessage { Param ( [Parameter(Mandatory=$true, Position=0)]$Text, $Url = "https://hooks.slack.com/services/xxxxx", # Param

我正在尝试编写一个PowerShell函数来调用Slack webhook。我从中获取了函数,但该函数似乎由于解析错误而失败。我还删除了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
}
错误是:

At line:12 char:67 + ... y = @{ text=$Text; channel=$Channel; username=$Username; icon_emoji=$ ... + Missing '=' @{ text=$Text; channel=$Channel; username=$Username; icon_emoji=$ ... The hash literal was incommplete. + CategoryInfo :ParserError (:) [], ParentContainsErrorRecordException + FillyQualifiedErrorId : MissingEqualsInHashLiteral 第12行字符:67 + ... y=@{text=$text;channel=$channel;username=$username;icon_emoji=$。。。 + 缺少“=”@{text=$text;channel=$channel;username=$username;icon_emoji=$。。。 哈希文本不完整。 +CategoryInfo:ParserError(:)[],ParentContainerRorRecordException +FillyQualifiedErrorId:MissingEqualsInHashLiteral
函数名在哪里?第二个参数后缺少一个逗号,最后一个参数后有一个额外的逗号

function whatever ()
{
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
}

我想可能我的函数格式不正确?我确实检查了我的原始代码,参数中的逗号是正确的。sry,在没有复制/粘贴可用的VM上工作。似乎错误来自“正文”函数的一部分。我确实更改了函数调用的格式。仅供参考,但现在有一个PowerShell模块可用于此功能:。找到了代码。