Get SharePoint List Flow Details using PowerShell

Get SharePoint List Flow Details using PowerShell

Power Automate Flows created against SharePoint Online lists/libraries get stored in the same default environment as all other flows. This can lead to confusion and frustration in cases where you need to know which ones are SharePoint-related and which are not. Fortunately, there’s an easy way to find those using PowerShell!

Requirements

  • PowerShell 3.x or higher (launched as Administrator if you need the below module)
  • Install-Module Microsoft.PowerApps.Administration.PowerShell

Script

$tenantID='your-tenant-id'
Add-PowerAppsAccount -TenantID $tenantID
$e = Get-AdminPowerAppEnvironment
$results = @()
################################ FLOWS ################################
$flows = Get-AdminFlow -EnvironmentName $($e.EnvironmentName)
foreach($f in $flows){
    $ff = Get-AdminFlow -EnvironmentName $($e.EnvironmentName) -FlowName $f.FlowName
    $isSP = $false
    $siteUrl = ""
    $listId = ""
    foreach($r in $ff.Internal.properties.referencedResources){
        if($r.service -eq "sharepoint" -and $r.resource.list -ne $null){
            $isSP = $true;
            $siteUrl = $($r.resource.site)
            $listId = $($r.resource.list)
            break;
        }
    }
    $arrDate = $($f.CreatedTime -split 'T')
    $arrTime = $($arrCreatedDate[1].Substring(0,8))
    $arrLMDate = $($f.LastModifiedTime -split 'T')
    $arrLMTime = $($arrLMDate[1].Substring(0,8))
    if($ff.Internal.properties.connectionReferences -ne $null){
        $conns = $ff.Internal.properties.connectionReferences | Get-Member -MemberType NoteProperty
        foreach($cr in $conns){
            $rawdata = $($cr.Definition -split "=@{")[1]
            $propdata = ConvertFrom-String $rawdata
            $connectorId = if([datetime]$ff.CreatedTime -ge [datetime]"06/08/2023 00:00") { $($propdata.P3) } else { $($propdata.P4) }
            $connectorDisplayName = if([datetime]$ff.CreatedTime -ge [datetime]"06/08/2023 00:00") { if($($propdata.P4) -match "=") { $($($propdata.P4 -split '=')[1].Trim(';')) } else { $($propdata.P4) } } else {  if($($propdata.P5) -match "=") { $($($propdata.P5 -split '=')[1].Trim(';')) } else { $($propdata.P5) } }
            $flow = [PSCustomObject]@{
                Environment=$e.DisplayName
                FlowName=$ff.FlowName
                FlowDisplayName=$ff.DisplayName
                OwnerId=$ff.CreatedBy.objectId
                Created=$([datetime]::parseexact($arrDate[0] + " " + $arrTime, 'yyyy-MM-dd HH:mm:ss', $null))
                Modified=$([datetime]::parseexact($arrLMDate[0] + " " + $arrLMTime, 'yyyy-MM-dd HH:mm:ss', $null))
                ConnectorName=$connectorDisplayName
                ConnectorId=$connectorId
                Site=$siteUrl
                ListId=$listId
            }
            $results += $flow 
        }
    }
}
$results | ogv

Leave a Reply

Your email address will not be published. Required fields are marked *