Hello friends!
There is a simple way to pass commands to your slack channel via Webhook API combined with PowerShell and JSON converter 🙂
Sounds complicated? A 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 USERNAMEHERE -Properties * | Select-Object DisplayName,LockedOut,SamaccountName,UserPrincipalName,Co
# Using Slack format with commas
$ad = '```' + ($ad | Format-Table | Out-String) + '```'
Set-StrictMode -Version Latest
$payload = @{
"channel" = "#yourslackchannel"
"icon_emoji" = "emojiifyouwant"
"text" = "This is the query you asked me to run :justdoit: : $ad"
"username" = "NAME"
}
Invoke-WebRequest `
-Body (ConvertTo-Json -Compress -InputObject $payload) `
-Method Post `
-Uri "YOURWEBHOOKURL" | Out-Null
How cool is that ? We can create a whole quantity of easy automation & reports using that !
1 Comment
WINDA EKA SAMODRA · July 7, 2019 at 6:25 AM
Where i can get the Webhook API?