I need a bit of help as I couldn't find an answear on the open topics related to how exactly to send the powershell results to a slack channel.
For a bit of context, I'm remoting to a server trying to get different information like read some files or status of services and instead of sending an email with the resutls I thought it will be good to post the results directly to a slack channel.
I tried the following simple command, but I'm missing something on how posting to slack channel via webhook app works.
$Results = Get-Service Service* -ComputerName
Send-SlackMessage -Uri <webhook URI> -Text $Results
The above scripts doesn't work unfortunatlly. Would you be able to help me understand how exactly the slack message function should be setup in orde to send the results from powershell to the slack channel?
Thank you! M
CodePudding user response:
Differences between Windows PowerShell 5.1 and PowerShell 7.x Please Note In Windows 7.2 the Get-Service command made use of DCOM and such functionality like '-ComputerName' is removed.
$server = $env:Computername
Invoke-Command -Computername $server -Scriptblock {Get-Service | where status -eq 'started;}
A simple function to send messages to Slack can be found here -
PowerShell and a Slack API Webhook
https://mufana.github.io/blog/2018/04/13/PoshSlackHook
Get-Service cmdlet
The cmdlet gets the members, the properties and methods, of objects
get-service | get-member | sort Name
Names of services that start / contain 'App'
$Results = Get-Service -Name App | Select Name