如何从Powershell向Slack发布消息

时间:2016-10-11 20:24:38

标签: powershell-v2.0 slack-api

我正在寻找一个使用HttpClient发布到Slack通道的PowerShell代码的简单示例。

1 个答案:

答案 0 :(得分:3)

Add-Type -AssemblyName System.Net.Http
$http = New-Object -TypeName System.Net.Http.Httpclient
$message = "Hello world."
$httpMessage = "{""text"": """ + $message + """}";
$content = New-Object -TypeName System.Net.Http.StringContent($httpMessage)
$httpResult = $http.PostAsync("https://hooks.slack.com/services/your_channel_url_here", $content).Result