Share via


Sharepoint Online: Manage your flows using PnP cmdlets

Introduction

Managing your flows using PnP is fabulously easy. Faster to code than CSOM, more options than classic SharePoint Online Management Shell.

Get

Get All Flows

$environment = Get-PnPPowerPlatformEnvironment
Get-PnPFlow -Environment $environment

Get Flows and their Properties

If you notice, the output from the previous cmdlet has a property called Properties. You can expand it to view more 

Get-PnPFlow -Environment $environment | select -expandProperty Properties

ApiId                      : /providers/Microsoft.PowerApps/apis/shared_logicflows
DisplayName                : Projekt archivieren
StateRaw                   : Started
State                      : Started
SharingTypeRaw             :
SharingType                :
CreatedTime                : 4/12/2022 2:09:34 PM
LastModifiedTime           : 4/12/2022 2:40:37 PM
FlowSuspensionReason       :
DefinitionSummary          : PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate.FlowDefinitionSummary
Creator                    : PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate.FlowCreator
ProvisioningMethod         : FromDefinition
FlowFailureAlertSubscribed : True
WorkflowEntityId           :
UserType                   : Owner
Environment                :
EnvironmentDetails         : PnP.PowerShell.Commands.Model.PowerPlatform.Environment.Environment
TemplateId                 :

Get Flow Actions

The same cmdlet allows you to see more details about the flow, like actions and creator details.

$props = Get-PnPFlow -Identity 5e904726-e098-41f4-a96a-066652abc113 -Environment $environment | select -ExpandProperty Properties
$props.DefinitionSummary.Actions

Type               Kind SwaggerOperationId
----               ---- ------------------
OpenApiConnection       HttpRequest
OpenApiConnection       PatchItem
OpenApiConnection       CreateNewFolder
InitializeVariable
OpenApiConnection       CreateNewFolder
Wait
OpenApiConnection       GetAllTables
Foreach
InitializeVariable
OpenApiConnection       HttpRequest
InitializeVariable
Foreach
If
OpenApiConnection       CreateNewFolder
SetVariable

Get Flow Creator Details

The Get-PnPFlow cmdlet allows you to see more details about the flow, like actions and creator details. Based on UserId you can identify who created the flow.

$props = Get-PnPFlow -Identity 5e904726-e098-41f4-a96a-066652abc113 -Environment $environment | select -ExpandProperty Properties
$props.Creator | fl

TenantId : 7f14efbc-9e1d-4f3f-99cd-01eccf994443
ObjectId : 6c1db2ba-f637-4f06-8b81-ba6e383b6aa1
UserId   : 6c1db2ba-f637-4f06-8b81-ba6e383b6aa1
UserType : ActiveDirectory

Using the ObjectId you can retrieve the user from Azure Active Directory:

Get-MsolUser | where {$_.ObjectId -eq $props.Creator.ObjectId}

Get a list of flow authors

Using the same logic, you can check who creates flows in your environment

$flows = Get-PnPFlow -AsAdmin -Environment $environment | select -ExpandProperty Properties
foreach($flow in $flows){ Get-MsolUser | where {$_.ObjectId -eq $flow.Creator.ObjectId} }

Bonus

Have a look at these bonus scripts / solutions, and find out the most popular actions used in flows and the most frequent flow authors.
Power Automate: Get most frequently used actions
Power Automate: Get users who create most flows

Remove

You can remove unwanted flows using Remove-PnPFlow cmdlet.

Remove Single Flow

$environment = Get-PnPFlowEnvironment
Remove-PnPFlow -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182

Clean All Flows from the Environment

$environment = Get-PnPPowerPlatformEnvironment
$Flows = Get-PnPFlow -Environment $environment
 
foreach($flow in $flows){
    Remove-PnPFlow -Environment $environment -Identity $flow.Id
}

Export

Using flow's name you can export it.

Export flow in JSON format to the console

$MyFlows = Get-PnPFlow -AsAdmin -Environment $environment
Export-PnPFlow -Environment $environment -Identity $MyFlows[1].Name

Export Flow as zip package

$MyFlows = Get-PnPFlow -AsAdmin -Environment $environment
Export-PnPFlow -Environment $environment -Identity $MyFlows[1].Name -AsZipPackage

Disable 

If you disable a flow, it will change its State to Stopped

Disable-PnPFlow -Environment $environment -Identity 6301686e-5fe4-43fe-bef4-439a490ccf8f

Enable

If you enable a flow, it will change its State back to Started.

Enable-PnPFlow -Environment $environment -Identity 6301686e-5fe4-43fe-bef4-439a490ccf8f  -AsAdmin

See Also

PnP cmdlets

https://c.statcounter.com/12754273/0/6e227484/0/