如何 post 从 Powershell 向 Slack 发送消息

How to post a message to Slack from Powershell

我正在寻找使用 HttpClient post 到 Slack 频道的 PowerShell 代码的简单示例。

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