Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active February 13, 2021 01:09
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save magnetikonline/11007e42d86f490b84f8 to your computer and use it in GitHub Desktop.
Save magnetikonline/11007e42d86f490b84f8 to your computer and use it in GitHub Desktop.
PowerShell push message to Slack incoming webhook.
Set-StrictMode -Version Latest
$payload = @{
"channel" = "#my-channel"
"icon_emoji" = ":bomb:"
"text" = "This is my message. Hello there!"
"username" = "Mr. Robot"
}
Invoke-WebRequest `
-Body (ConvertTo-Json -Compress -InputObject $payload) `
-Method Post `
-Uri "https://hooks.slack.com/services/HOOK_API_SLUG" | Out-Null
@rifaterdemsahin
Copy link

getting this error

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again. At D:\a_temp\f0550799-da8e-4f01-b1cf-9f5bdbca4354.ps1:10 char:1 + Invoke-WebRequest ` + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException + FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestComman d

@magnetikonline
Copy link
Author

@rifaterdemsahin the error pretty much covers the issue. You need to run the IE first-launch config.

A quick google gives heaps of results - e.g. http://wahlnetwork.com/2015/11/17/solving-the-first-launch-configuration-error-with-powershells-invoke-webrequest-cmdlet/

Run IE on target machine at least once to config.

@edhaack
Copy link

edhaack commented Mar 22, 2019

or... just use the -UseBasicParsing switch.

@pixelbath
Copy link

As an alternative to Invoke-WebRequest, you can use the (already built-in) Invoke-RestMethod:

Invoke-RestMethod -Uri "https://hooks.slack.com/services/HOOK_API_SLUG" -Method Post -Body $payload -ContentType "application/json"

@magnetikonline
Copy link
Author

Thanks @pixelbath, nicely noted 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment