GitHub Icon Image
GitHub

Get Flows Connected to SharePoint

Summary

This script will generate a csv listing all flows which connect to SharePoint.

  • Power Apps PowerShell
$environment="{Your EnvironmentName}"
Connect-AzureAD
$flows=Get-AdminFlow -EnvironmentName $environment
$results=@()
foreach ($flow in $flows){

    $flowdetail=Get-AdminFlow  -EnvironmentName  $environment -FlowName $flow.FlowName

    foreach($referencedrsource in $flowdetail.Internal.properties.referencedResources){
    
    if ($referencedrsource.service -eq 'sharepoint'){
        $creator =  Get-AzureADUser -ObjectId  $flowdetail.Internal.properties.creator.objectId
        $flowdetail.DisplayName
        $canedit=Get-AdminFlowOwnerRole  -EnvironmentName  $environment -FlowName $flow.FlowName |Where-Object {$_.RoleType -eq "CanEdit"}
        $editUsers=""
        $canedit
        if ($canedit -ne $null){
            if ($canedit -is [array]){
                foreach($edituser in $canedit){
                   if ($edituer.PrincipalType -eq 'User'){
                       $editorName+=  (Get-AzureADUser -ObjectId  $edituser.PrincipalObjectId).UserPrincipalName + "; "
                   }
                   if ($canedit.PrincipalType -eq 'Group'){
                      $editorName=  (Get-AzureADGroup -ObjectId  $edituser.PrincipalObjectId).DisplayName + "; "
                    }

                }
            }
            else{
               if ($canedit.PrincipalType -eq 'User'){
                   $editorName=  (Get-AzureADUser -ObjectId  $canedit.PrincipalObjectId).UserPrincipalName
               }
               if ($canedit.PrincipalType -eq 'Group'){
                   $editorName=  (Get-AzureADGroup -ObjectId  $canedit.PrincipalObjectId).DisplayName
               }
            }
        }
        $owner=Get-AdminFlowOwnerRole  -EnvironmentName  $environment -FlowName $flow.FlowName |Where-Object {$_.RoleType -eq "Owner"}
        $ownerName=""
        if ($owner.PrincipalType -eq 'User'){
           $ownerName=  (Get-AzureADUser -ObjectId  $owner.PrincipalObjectId).UserPrincipalName
        }
        if ($owner.PrincipalType -eq 'Group'){
           $ownerName=  (Get-AzureADGroup -ObjectId  $owner.PrincipalObjectId).DisplayName
        }
        

        $results += [pscustomobject]@{Name=$flow.FlowName;DisplayName=$flowdetail.DisplayName;Site=$referencedrsource.resource.site;List=$referencedrsource.resource.list;Creator=$creator.UserPrincipalName;Owner=$ownerName;State=$flowdetail.Internal.properties.state;SuspensionReason=$flowdetail.Internal.properties.flowSuspensionReason;Created=$flowdetail.Internal.properties.createdTime;lastModified=$flowdetail.Internal.properties.lastModifiedTime;Editors=$editorName}
    
    }
    }


}
$results | Export-Csv -NoTypeInformation -Path [locationOfYourCsv]

Check out the Power Apps PowerShell to learn more at: https://learn.microsoft.com/power-platform/admin/powerapps-powershell

Contributors

Author(s)
Russell Gove

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI