Find Power Automate Flows that are connected to your site or list

Find Power Automate Flows that are connected to your site or list  header image

One of my colleagues recently had some troubles at a customer: there was a SharePoint list that had its items updated by a Power Automate process. However, it was unclear what flow did the update. Given the size of the environment with multiple environments and multiple flow per environment we just could not figure out what flow was the culprit. So we discussed some scripting options and ended up automating it with the CLI for Microsoft 365.

CLI for Microsoft 365 to scan Flows

Using the CLI you can work with the Power Platform, there is even a sample that allows you to export all flows. That got me thinking about using this approach to check what flows are present in an environment and scan through the contents of this flow. The sample script is straightforward:

  • Get all environments and loop through them.
  • Get all flows per environment and export them.
  • Scans the exported flow for the required search string and delete the downloaded file.
  • Report all flows that contains the search string.

The sample script is as follows:

Write-Output "Retrieving all environments"

$environments = m365 flow environment list -o json | ConvertFrom-Json
$searchString = "15f5b014-9508-4941-b564-b4ab1b863a7a" #listGuid
$path = "exportedflow.json";

ForEach ($env in $environments) {
    Write-Output "Processing $($env.displayName)..."

    $flows = m365 flow list --environment $env.name --asAdmin -o json | ConvertFrom-Json

    ForEach ($flow in $flows) {
        Write-Output "Processing $($flow.displayName)..."
        m365 flow export --id $flow.name --environment $env.name --format json --path $path

        $flowData = Get-Content -Path $path -ErrorAction SilentlyContinue

        if($null -ne $flowData) {
            if ($flowData.Contains($searchString)) {
                    Write-Output $($flow.displayName + "contains your search string" + $searchString)
                    Write-Output $flow.id
            }

            Remove-Item $path -Confirm:$false
        }
    }
}

Executing the script provides you a list of all flows that contains your search string.

Flows that contains the search string

You can add any string to search the JSON for. In the script sample the list GUID is added, but you can also use something like $searchString = "https://contoso.sharepoint.com/sites/mysite"; to find any flow that has a connection to a specific site collection. Or you can add the name of your environment variables if you are looking for those. I hope this sample helps you in finding whatever flow might be running wild on your environment🔥.

Loading comments…