Introduction

Webhooks are one of the ways applications communicate with each other. Unlike API which is request-based, Webhook is event-based. Picture Webhooks as a type of API that is driven by events rather than requests. This means that an application sends data to another as soon as an event takes place.

Let's look at this simple scenario. You want to receive Teams notification when posts that mention your accounts on Facebook are published. Rather than constantly asking Facebook for new posts that satisfy these conditions, it makes much more sense for Facebook to send a notification to Microsoft Teams only when this event happens.

In this article, we will create an alert system for Microsoft teams which checks and notifies us on the Microsoft Teams channel. To do this, we will use Microsoft Teams webhook to send a message via the HTTP methods. We will implement this with a Powershell Script with the following steps:

  1. Generate webhook from Microsoft Teams
  2. Check a service with Powershell
  3. Send a message to Teams when service is not running
  4. Create a Windows Scheduler Task to run the Powershell Script every 10 minutes
Windows win32_service AppMgmt SERVICE >_ PowerShell Get-WmiObject Invoke-WebRequest SCRIPT Webhook HTTP POST JSON payload BRIDGE T Teams #general Channel DELIVERY ALERT Service Down NOTIFY

Understanding Webhooks

Webhooks are one of the ways applications communicate with each other. Unlike API which is request-based, Webhook is event-based. Picture Webhooks as a type of API that is driven by events rather than requests. This means that an application sends data to another as soon as an event takes place.

Key difference: With APIs, your application must constantly poll for new data. With Webhooks, the source application pushes data to you as soon as an event occurs — no polling required.

In our case, we want to be notified on Microsoft Teams whenever a Windows service goes down. Instead of manually checking, we'll set up a PowerShell script that monitors the service and sends an alert via a Webhook URL whenever the service is not running.

Generate Incoming Webhook

To get started, we need to generate a webhook URL from Microsoft Teams that our PowerShell script can send messages to.

Configure Microsoft Teams

Open Microsoft Teams app and go to the channel where you would like to add the webhook and select ••• More options from the top navigation bar.

  1. Select Connectors from the dropdown menu.
  2. Search for Incoming Webhook and select Add.
  3. Select Configure, provide a name, and upload an image for your webhook if you want.
  4. The dialog window presents a unique URL that maps to the channel. Copy and save the webhook URL to send information to Microsoft Teams and select Done.

Important: Copy and save the webhook URL carefully. This unique URL is what maps to your specific Teams channel and will be used in the PowerShell script to post messages.

Now, we can make use of this URL in our PowerShell script to post messages to Microsoft Teams.

Checking Windows Services with PowerShell

The first thing we need to do is to open PowerShell and run as an administrator. Send each of the following commands in each steps below;

Step 1: Get-Help *-Service

To download all the Packages needed to run Power Script.

PowerShell
Get-Help *-Service

Step 2: Check Service Status

The arrow points to the name of the service we're trying to check if it's presently running.

PowerShell
Get-Service -Name AppMgmt | Select-Object -Property *
MONITORING CYCLE ? Check Service Get-WmiObject Running? No → Alert Send Alert Invoke-WebRequest Wait 10 minutes LOOP Repeat

Sending Teams Alerts

We will write our script in PowerShell which helps to check if our services are running and if not, it alerts us on Teams.

PowerShell
#this checks if the service AppMgmt isn't running 
$NotRunning = Get-WmiObject win32_service -Filter "name='AppMgmt' AND State!='Running' AND StartMode='Manual'" -ComputerName Desktop-UDLkk | Select-Object name, State, StartMode

#we'll make use of the if function to check if the service isn't running and if not it runs the code in it, which is to send message to us on Teams
#we indicate the payload we'll be using along with our request

If ($NotRunning) {
$payload = @{
 "channel" = "#general"
  "text" = "Alert!!! your Alteryx server is down"
}

#then we invoke web request using the uri which is the Teamswebhook url alongside the post method to send our request

Invoke-WebRequest -UseBasicParsing `
 -Body (ConvertTo-Json -Compress -InputObject $payload) `
 -Method Post `
 -Uri "https://cndrocom.webhook.office.com/webhookb2/bb92ccc0-3207-4ed9-8f23-080e2c3b05db@f7ab8bd8-7f80-4ddb-8b92-2d6e189fa78e/IncomingWebhook/6acc857fd43d48ad94e9f2324421e9e5/ab4c11d9-2ab5-47da-8f83-c57f2e8d97e3"

 Write-Output "The condition was true"
}

Afterwards, our message will be sent successfully whenever this code is executed.

Automating with Windows Task Scheduler

Also, if we want a situation whereby we don't want to do things manually, we can make our script automated. This script will run every 10 minutes to alert us if any of our services isn't running on Teams.

This will be implemented using the windows task scheduler.

To get started, we search for task scheduler on our system, we then click on create task.

Lastly, let's specify a name for our task. Also, click on trigger, action and the settings tab to indicate how we want our task to be. Afterwards the task will start automatically which means an alert will be sent to us via Teams every 10 minutes.

TASK SCHEDULER TIMELINE 10:00 OK 10:10 OK 10:20 OK ! 10:30 ALERT! Service Down ... 10:40 Pending 10 min 10 min 10 min 10 min Windows Task Scheduler runs PowerShell script at every interval

Conclusion

We have successfully created an alert system that monitors Windows services and sends notifications to Microsoft Teams using PowerShell and Incoming Webhooks. The system checks service status, sends alerts when a service goes down, and can be automated to run every 10 minutes using Windows Task Scheduler.

This approach gives you a lightweight, code-driven monitoring solution that integrates directly with your team's communication channel — no additional monitoring software required.