If you work with Microsoft Power Platform, you’ve likely experienced the frustration of a well-functioning automated flow suddenly failing and leaving you puzzled as you search for the cause. Often, broken connections are the hidden issue. Whether they expire or fail unexpectedly, these connection problems can disrupt your automated or scheduled cloud flows, causing your processes to break down. You may have error handling and alerting set up within your flows using Microsoft Teams or Outlook connectors, but these can also fail if the connection behind the connector isn’t working.
Unfortunately, Power Platform doesn’t offer a straightforward way to monitor these connections or alert you when they fail. Even integrating with Application Insights doesn’t fill this gap.
Here’s the good news: By utilizing the PowerApps Administration PowerShell Module, you can access detailed connection statuses. I’ve developed a simple Azure DevOps Pipeline that automates the monitoring of these connections in a specific environment and sends alerts if any issues are detected.
Setting Up the Pipeline
Our goal is to create an Azure DevOps Pipeline that:
- Runs on a schedule (e.g., daily at midnight),
- Checks the status of Power Platform connections in specified environments,
- Sends alerts if any connections are failing.
Let’s break down each component of the pipeline and understand how it works.
1. Setting Up the Pipeline Trigger and Schedule
trigger:
- none
schedules:
- cron: "0 0 * * *" # Triggers every day at midnight UTC
displayName: Daily Trigger
branches:
include:
- main
always: true
batch: false
Now, let’s define the stage of our pipeline where we’ll check the connections and install the required PowerShell modules.
stages:
- stage: CheckConnections
jobs:
- job: CheckConnectionsJob
steps:
- powershell: |
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -AllowClobber -Scope CurrentUser
Install-Module -Name Microsoft.PowerApps.PowerShell -Force -AllowClobber -Scope CurrentUser
displayName: 'Install PowerApps Modules'
Now let’s run our PowerShell script to check the connections in our environment. We call checkConnectionStatusesScript.ps1 with parameters for our environment. After running the script, we publish the results so they can be accessed in the next step.
- powershell: |
.\checkConnectionStatusesScript.ps1 `
-EnvironmentId "$(environment-id)" `
-UserName "$(user-name)" `
-UserPassword "$(user-password)" `
-UserObjectId "$(user-object-id)" `
-OutputFilePath "$(Build.ArtifactStagingDirectory)\connection_errors.json"
displayName: 'Check Power Platform Connections'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'connection_check'
displayName: 'Publish Artifact: connection_check'
3. Evaluating the Connection Status and Sending Alerts
Finally, we evaluate the results and determine whether to fail the pipeline stage intentionally, which can trigger notifications.
- powershell: |
$jsonResult = Get-Content "$(Build.ArtifactStagingDirectory)\connection_errors.json" | ConvertFrom-Json
$hasErrors = $jsonResult.hasErrors
if ($hasErrors -eq $true) {
Write-Output "Connection errors detected. This step will intentionally fail to trigger an alert."
Write-Output "Errors found:"
$jsonResult.errorConnections | ForEach-Object { Write-Output $_ }
Write-Output "##vso[task.complete result=Failed;]Connection errors detected."
} else {
Write-Output "No connection errors detected."
}
displayName: 'Evaluate Connection Statuses'
PowerShell Script
We used a PowerShell script (checkConnectionStatusesScript.ps1) that performs the actual connection check. Let’s dive into it.
1. Parameters and Module Imports and Authentication
param (
[string]$EnvironmentId,
[string]$UserName,
[string]$UserPassword,
[string]$UserObjectId,
[string]$OutputFilePath
)
Import-Module Microsoft.PowerApps.Administration.PowerShell -Verbose
Import-Module Microsoft.PowerApps.PowerShell -Verbose
$securePassword = ConvertTo-SecureString $UserPassword -AsPlainText -Force
Add-PowerAppsAccount -Username $UserName -Password $securePassword
2. Retrieving Connections and Checking for Connection Errors
We can retrieve all connections in the specified environment and filter connections to those created by a specific user (identified by User Entra Id ObjectId).
$connections = Get-AdminPowerAppConnection -EnvironmentName $EnvironmentId
$filteredConnections = $connections | Where-Object { $_.CreatedBy.id -eq $UserObjectId }
$errorConnections = @()
$hasErrors = $false
foreach ($connection in $filteredConnections) {
foreach ($status in $connection.Statuses) {
if ($status.status -eq "Error") {
$errorConnections += $connection
$hasErrors = $true
break
}
}
}
3. Compile and Output Results as JSON
Use ConvertTo-Json to serialize the results and output them to the specified file:
$result = @{
"hasErrors" = $hasErrors
"errorConnections" = $errorConnections | ForEach-Object {
@{
"DisplayName" = $_.DisplayName
"ConnectionId" = $_.ConnectionId
"FullConnectorName" = $_.FullConnectorName
"CreatedBy" = $_.CreatedBy
"Statuses" = $_.Statuses | ForEach-Object { $_.status }
}
}
}
$result | ConvertTo-Json -Compress | Out-File -FilePath $OutputFilePath
Here you may also log each connection detail to identify connection errors:
Set Up Notifications
By intentionally setting the pipeline stage as failed when errors are detected, you can leverage Azure DevOps notifications to trigger an alert. Notifications can be sent directly to specific team members or to a custom email address, such as that of a MS Teams channel. This ensures that if a connection fails, the right people are notified to take action.
The email you receive appears as shown below. By clicking “Show Results” you can view the logs to identify the details of the broken connections.
I hope this approach is as beneficial for you as it has been for me. By automating Power Platform connection monitoring, we can focus on creating value and spend less time dealing with unforeseen issues. Don’t hesitate to adapt this pipeline to fit your unique needs, and feel free to share your experiences!