Get-Ryan

[PowerShell] Write-Slack

Jan 8th, 2016
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Write-Slack {
  2.  
  3.     [cmdletbinding()]
  4.  
  5.     Param(
  6.             [string]
  7.             $Username = "<Default Username>",
  8.  
  9.             [string]
  10.             $Channel = "<Default Channel>",
  11.  
  12.             [parameter(Mandatory=$true)]
  13.             [string]
  14.             $Text
  15.  
  16.  
  17.          )
  18.  
  19.     $Body = New-Object -TypeName PSObject -Property @{'username'=$Username;
  20.                                                       'channel'=$Channel;
  21.                                                       'text'=$Text}
  22.  
  23.     $uri = "<Webhook URL provided by Slack>"
  24.  
  25.     Invoke-RestMethod -Method Post -Uri $uri -Body (ConvertTo-Json $Body)
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment