Migrating Classic SharePoint Workflows to Power Automate using PnP PowerShell

Loading

With Microsoft’s deprecation of SharePoint 2010 and 2013 workflows, organizations must transition to Power Automate for modern workflow automation. Migrating workflows manually can be time-consuming, but PnP PowerShell provides an efficient way to identify, extract, and automate workflow migration.

In this guide, we’ll cover step-by-step instructions to:

  • Identify existing classic SharePoint workflows.
  • Export workflow details for analysis.
  • Automate migration to Power Automate.

Step 1: Identifying Classic SharePoint Workflows

1. Connect to SharePoint Online

Before retrieving workflow data, connect to SharePoint using PnP PowerShell.

$siteUrl = "https://yourtenant.sharepoint.com/sites/YourSite"
Connect-PnPOnline -Url $siteUrl -Interactive

✔ Establishes a secure authenticated connection to SharePoint.


2. Retrieve List of Workflows in the Site

Run the following script to list all workflows (including SharePoint 2010/2013 workflows):

$workflows = Get-PnPWorkflowInstance
$workflows | Select Name, Status, ListName, Created, Modified

✔ Helps you identify workflows in use.


3. Check Workflow Association with Lists and Libraries

Identify which lists or libraries are using SharePoint workflows.

$lists = Get-PnPList
foreach ($list in $lists) {
$workflows = Get-PnPWorkflowInstance -List $list
foreach ($wf in $workflows) {
Write-Host "Workflow: $($wf.Name) | Status: $($wf.Status) | List: $($list.Title)"
}
}

✔ Helps determine which workflows need migration.


Step 2: Exporting Workflow Definitions for Analysis

Before migrating, extract workflow configurations into a CSV file for analysis.

$workflowData = @()
foreach ($wf in $workflows) {
$workflowData += [PSCustomObject]@{
Name = $wf.Name
Status = $wf.Status
ListName = $wf.ListName
Created = $wf.Created
Modified = $wf.Modified
}
}

$workflowData | Export-Csv -Path "C:\Migration\WorkflowExport.csv" -NoTypeInformation
Write-Host "Workflow export completed."

✔ Creates a detailed report of all workflows.


Step 3: Mapping SharePoint Workflows to Power Automate

1. Identify Common Workflow Actions

Review workflow actions to determine their equivalents in Power Automate:

Classic Workflow ActionPower Automate Equivalent
Send EmailSend an Email (Outlook, Gmail)
Create List ItemCreate Item in SharePoint
Update List ItemUpdate Item in SharePoint
Start WorkflowTrigger Flow Based on Condition
Wait for ApprovalStart and Wait for Approval
Assign TaskCreate Approval Request

✔ Ensures seamless migration of workflow actions.


Step 4: Automating Workflow Migration to Power Automate

1. Convert SharePoint Workflows to JSON for Power Automate

To create Power Automate workflows, first convert workflow logic into JSON format.

$json = @"
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/workflows",
"actions": {
"Send_an_email": {
"type": "SendEmail",
"inputs": {
"email": "@{triggerBody()['Email']}",
"subject": "Workflow Notification",
"body": "Your request has been processed"
}
}
}
}
}
"@
$json | Set-Content -Path "C:\Migration\NewFlow.json"

✔ Creates a Power Automate template in JSON format.


2. Deploy Workflow to Power Automate

Use Power Automate API to deploy workflows automatically.

$flowName = "Migrated Workflow"
$environment = "Default-environment"
$flowFile = "C:\Migration\NewFlow.json"

$apiUrl = "https://api.flow.microsoft.com/providers/Microsoft.Logic/workflows/$flowName"
Invoke-RestMethod -Uri $apiUrl -Method Post -Headers @{
"Authorization" = "Bearer $accessToken"
"Content-Type" = "application/json"
} -Body (Get-Content $flowFile -Raw)

✔ Automates workflow creation in Power Automate.


Step 5: Testing and Validating Migrated Workflows

After migration, test workflows by:

  1. Manually triggering the workflow in Power Automate.
  2. Checking error logs in Power Automate Run History.
  3. Comparing outputs between SharePoint workflow and Power Automate.

Step 6: Removing Old Workflows

After successful migration, disable old workflows to prevent conflicts.

foreach ($wf in $workflows) {
Stop-PnPWorkflowInstance -Identity $wf.Id
Write-Host "Workflow $($wf.Name) has been stopped."
}

✔ Ensures that classic workflows are deactivated.

Leave a Reply

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