Last active
April 15, 2018 04:39
-
-
Save giseongeom/62b1acbface122114c70a99e2daf576d to your computer and use it in GitHub Desktop.
Notification into slack (incoming webhook)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $slack_uri_default = 'https://hooks.slack.com/services/' | |
| # Notification via Slack | |
| function Notify-Slack() | |
| { | |
| param | |
| ( | |
| [Parameter(Mandatory=$true)] | |
| $text, | |
| [Parameter(Mandatory=$false)] | |
| $channel='#slack-webhook-testing', | |
| [Parameter(Mandatory=$false)] | |
| $username="AzureOps", | |
| [Parameter(Mandatory=$false)] | |
| $slack_url=$slack_uri_default | |
| ) | |
| $slack_msg = New-Object psobject | |
| $slack_msg | Add-Member -MemberType NoteProperty -TypeName string -Name text -Value $text | |
| $slack_msg | Add-Member -MemberType NoteProperty -TypeName string -Name channel -Value $channel | |
| $slack_msg | Add-Member -MemberType NoteProperty -TypeName string -Name username -Value $username | |
| $slack_msg = ConvertTo-Json $slack_msg | |
| Invoke-WebRequest -Method Post -uri $slack_url -Body $slack_msg -ContentType "text/plain; charset=utf-8" | |
| } | |
| [string]$mymsg=@" | |
| Hello world | |
| "@ | |
| Notify-Slack -text $mymsg |
Author
giseongeom
commented
Apr 14, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment