{"id":221,"date":"2018-09-13T12:04:39","date_gmt":"2018-09-13T11:04:39","guid":{"rendered":"http:\/\/brgeek.com.br\/wordpress\/?p=221"},"modified":"2018-09-13T12:04:39","modified_gmt":"2018-09-13T11:04:39","slug":"throw-powershell-commands-via-webhook-to-your-slack-channel","status":"publish","type":"post","link":"http:\/\/brgeek.com.br\/wordpress\/2018\/09\/13\/throw-powershell-commands-via-webhook-to-your-slack-channel\/","title":{"rendered":"Throw Powershell commands via Webhook to your Slack Channel !"},"content":{"rendered":"<p>Hello friends!<\/p>\n<p>There is a simple way to pass commands to your slack channel via Webhook API combined with PowerShell\u00a0and JSON converter \ud83d\ude42<\/p>\n<p>Sounds complicated?\u00a0A few lines of code do the trick<\/p>\n<p><a href=\"http:\/\/brgeek.com.br\/wordpress\/wp-content\/uploads\/2018\/09\/giphy-facebook_s.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/brgeek.com.br\/wordpress\/wp-content\/uploads\/2018\/09\/giphy-facebook_s-300x169.gif\" alt=\"\" width=\"300\" height=\"169\" class=\"alignnone size-medium wp-image-222\" \/><\/a><\/p>\n<pre><code class=\"language-powershell\" data-line=\"\">\n\n#Using out-string just to display on Channel line by line if you want | out-string \n$ad = Get-ADUser USERNAMEHERE -Properties * | Select-Object DisplayName,LockedOut,SamaccountName,UserPrincipalName,Co\n\n# Using Slack format with commas\n$ad = &#039;```&#039; + ($ad | Format-Table | Out-String) + &#039;```&#039;\n\nSet-StrictMode -Version Latest\n\n$payload = @{\n\t&quot;channel&quot; = &quot;#yourslackchannel&quot;\n\t&quot;icon_emoji&quot; = &quot;emojiifyouwant&quot;\n\t&quot;text&quot; = &quot;This is the query you asked me to run :justdoit: : $ad&quot;\n\t&quot;username&quot; = &quot;NAME&quot;\n}\n\nInvoke-WebRequest `\n\t-Body (ConvertTo-Json -Compress -InputObject $payload) `\n    -Method Post `\n\t-Uri &quot;YOURWEBHOOKURL&quot; | Out-Null\n<\/code><\/pre>\n<p>How cool is that ? We can create a whole quantity of easy automation &#038; reports using that ! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello friends! There is a simple way to pass commands to your slack channel via Webhook API combined with PowerShell\u00a0and JSON converter \ud83d\ude42 Sounds complicated?\u00a0A few lines of code do the trick #Using out-string just to display on Channel line by line if you want | out-string $ad = Get-ADUser [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":149,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[34,28,8,23,6,26,27],"class_list":["post-221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-api","tag-json","tag-michael-goulart","tag-netherlands","tag-powershell","tag-slack","tag-webhook"],"jetpack_featured_media_url":"http:\/\/brgeek.com.br\/wordpress\/wp-content\/uploads\/2017\/09\/tips-tricks-hero-img.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":2,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":224,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/221\/revisions\/224"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media\/149"}],"wp:attachment":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}