Reviewing Power Automate Desktop (PAD) flows is harder than reviewing normal code. The logic lives inside the designer, spread across Main and many subflows, and there is no simple "view source" button that gives you the whole flow as one text file. For a code review, a diff between versions, or feeding the flow into a review checklist, you want plain text.
The good news: when you export a Power Platform solution, the desktop flow script (the Robin language you see when you copy actions out of the designer) is inside the .zip. This post shows a PowerShell script that opens one or many solution exports, finds every desktop flow, and saves each flow as a readable .txt file with Main first and then every subflow.
What the script does
| Step | Action | Detail |
|---|---|---|
| 1 | Collect solution files | $SolutionPath can be a single .zip or a folder - every .zip in the folder is processed |
| 2 | Unzip | Each solution is extracted to a time-stamped folder under %TEMP%, removed again at the end |
| 3 | Find desktop flows | Reads customizations.xml and picks every <Workflow> with Category = 6 (desktop flow) |
| 4a | Read the script (v2 schema) | Takes the flow's <Definition> element, strips the JSON quotes and unescapes \r\n, \uXXXX, etc. |
| 4b | Fallback (older exports) | Searches extracted files linked to the flow GUID (path or desktopflowbinary.xml) for text containing FUNCTION |
| 5 | Split into subflows | Regex finds each FUNCTION ... GLOBAL → END FUNCTION block; top-level code becomes Main |
| 6 | Save and log | One UTF-8 <FlowName>.txt per flow plus extraction_log.txt, and a summary printed to the console |
Where the flow code lives in a solution export
Microsoft introduced a new storage schema (v2) for desktop flows in Dataverse. As of October 1, 2024, the v1 schema is deprecated and v2 is enabled by default in all public regions, and new, modified or resaved desktop flows are stored in v2 (see Power Automate v2 schema). In v2 a desktop flow is made of several binaries, which is why Microsoft recommends Advanced > Add required objects before exporting a solution (see ALM for Power Automate v2 schema). The script handles both shapes:
| Export shape | Where the script looks | Logged source |
|---|---|---|
| Script stored on the workflow record | <Workflow><Definition> inside customizations.xml | customizations.xml <Definition> |
| Script stored in separate files | Extracted files whose path contains the flow GUID, or whose desktopflowbinary.xml references it | flow files |
Output
Each flow file looks like this - Main first, then every subflow in the order it appears:
FUNCTION Main GLOBAL
CALL Init
CALL Process_Records
END FUNCTION
FUNCTION Init GLOBAL
...
END FUNCTION
FUNCTION Process_Records GLOBAL
...
END FUNCTION
The console summary uses one line per item:
| Prefix | Meaning |
|---|---|
SOLUTION | Solution .zip processed and number of desktop flows found |
OK | Flow saved - subflow count, subflow names and output path |
EMPTY | Desktop flow found, but no script in the export (check "Add required objects") |
SKIP | The .zip has no customizations.xml - probably not a solution export |
ERROR | Unexpected error - full message also in extraction_log.txt |
How to run it
- In Power Automate, go to Solutions, open your solution and run Advanced > Add required objects on the desktop flow.
- Export the solution (managed or unmanaged) and copy the .zip into a folder, for example
C:\PAD_CodeReview_Toolkit\solution. - Open the script and set
$SolutionPathand$OutputFolderat the top. There is noparam()block on purpose, so you can run it line by line in PowerShell ISE or VS Code. - Run the script in Windows PowerShell 5.1 or PowerShell 7.
- Open the output folder - one
.txtper desktop flow, ready for review, diff or a code-review checklist.
Design notes
| Choice | Why |
|---|---|
Duplicate flow names get _<first 8 chars of GUID> | Two flows with the same display name never overwrite each other |
Header lines (@@, IMPORT, @SENSITIVE) removed from Main | They are metadata, not actions, and add noise to a review |
| Backslashes protected with a placeholder while unescaping | Paths like C:\temp\new are not broken into tab or new-line characters |
| Output written as UTF-8 without BOM, CRLF line endings | Opens cleanly in Notepad, VS Code and diff tools |
Temp folder removed in finally | No leftovers even when an error happens |
| Read-only on the source | The original solution .zip files are never modified |
Limitations
- The script reads only the flow logic. UI element selectors, images and connection references are not included.
- If a flow shows as
EMPTY, re-export after Add required objects so the flow binaries are inside the solution. - Solution export formats can change over time. If a future export stores the script differently, the fallback search is the place to extend.
Full script
Copy the script below, change the two paths at the top, and run it.
# =====================================================================
# Extract Power Automate Desktop (Robin) code from solution exports
# ---------------------------------------------------------------------
# Input : one solution .zip, or a folder that contains solution .zip files
# Output: one .txt per desktop flow (Main + every subflow) and a log file
# Run : edit the two paths below, then run the whole script or line by line
# =====================================================================
# Stop on any error so the catch block can log it
$ErrorActionPreference = 'Stop'
# ---- Settings: change these two paths ----
# A single solution .zip file OR a folder containing solution .zip files
$SolutionPath = 'C:\PAD_CodeReview_Toolkit\solution'
# Folder where the extracted flow scripts and the log are written
$OutputFolder = 'C:\PAD_CodeReview_Toolkit\robin_output'
# Load the .NET zip library used to unzip the solution
Add-Type -AssemblyName System.IO.Compression.FileSystem
# Create the output folder (no error if it already exists)
New-Item -ItemType Directory -Force -Path $OutputFolder | Out-Null
# Temporary working folder with a timestamp, removed again at the end
$WorkRoot = Join-Path $env:TEMP ('RobinExtract_' + (Get-Date -Format 'yyyyMMddHHmmss'))
New-Item -ItemType Directory -Force -Path $WorkRoot | Out-Null
# Log file and an in-memory summary that is printed at the end
$LogFile = Join-Path $OutputFolder 'extraction_log.txt'
$Summary = New-Object System.Collections.Generic.List[string]
# Regex that finds each subflow block:
# FUNCTION <name> GLOBAL ... END FUNCTION
# (?ms) = multi-line + dot matches new lines; .*? = shortest match per block
$FuncRegex = New-Object System.Text.RegularExpressions.Regex(
'(?ms)(?<![\w.])FUNCTION[ \t]+(\S+)[ \t]+GLOBAL[ \t]*$.*?^[ \t]*END FUNCTION\b')
# ---------------------------------------------------------------------
# Helper: write a time-stamped line to the log file
# ---------------------------------------------------------------------
function Write-Log([string]$Message) {
$line = (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') + ' ' + $Message
Add-Content -Path $LogFile -Value $line -Encoding UTF8
}
# ---------------------------------------------------------------------
# Helper: turn JSON-escaped text back into normal text
# (\uXXXX, \r\n, \n, \t, \" and \/ become real characters)
# ---------------------------------------------------------------------
function ConvertFrom-JsonEscaped([string]$Text) {
# Unicode escapes such as \u0027 -> '
$t = [regex]::Replace($Text, '\\u([0-9a-fA-F]{4})', { param($m) [string][char][Convert]::ToInt32($m.Groups[1].Value, 16) })
# Protect real backslashes (\\) with a placeholder so they are not mistaken for escapes
$t = $t.Replace('\\', [string][char]0)
# Convert the common escape sequences
$t = $t.Replace('\r\n', "`n").Replace('\n', "`n").Replace('\r', "`n").Replace('\t', "`t").Replace('\"', '"').Replace('\/', '/')
# Put the real backslashes back
return $t.Replace([string][char]0, '\')
}
# ---------------------------------------------------------------------
# Helper: read the flow script from a <Definition> value
# The value is a JSON string: "....\r\n...." - strip quotes and unescape
# ---------------------------------------------------------------------
function Get-DefinitionText([string]$Raw) {
$r = $Raw.Trim()
if ($r.StartsWith('"') -and $r.EndsWith('"')) {
$r = ConvertFrom-JsonEscaped ($r.Substring(1, $r.Length - 2))
}
# Normalise all line endings to `n for the parsing step
return ($r -replace "`r`n", "`n" -replace "`r", "`n")
}
# ---------------------------------------------------------------------
# Helper: split a full flow script into ordered subflows
# Main (top-level code that is not inside a FUNCTION) comes first,
# then each FUNCTION ... END FUNCTION block in the order found
# ---------------------------------------------------------------------
function Split-RobinScript([string]$Script) {
$result = [ordered]@{}
$matches2 = $FuncRegex.Matches($Script)
# Main = everything before the first FUNCTION block
$mainEnd = $Script.Length
if ($matches2.Count -gt 0) { $mainEnd = $matches2[0].Index }
# Drop header lines that are not real actions (@@ metadata, IMPORT, @SENSITIVE)
$mainLines = $Script.Substring(0, $mainEnd) -split "`n" | Where-Object {
$_ -notmatch '^\s*(@@|IMPORT\s|@SENSITIVE)'
}
$mainBody = ($mainLines -join "`n").Trim()
# Wrap Main in the same FUNCTION format as the other subflows
if ($mainBody) {
$result['Main'] = "FUNCTION Main GLOBAL`n" + $mainBody + "`nEND FUNCTION"
}
# Add every subflow once (first occurrence wins)
foreach ($m in $matches2) {
$name = $m.Groups[1].Value
if (-not $result.Contains($name)) { $result[$name] = $m.Value.Trim() }
}
return $result
}
# ---------------------------------------------------------------------
# Helper: save all subflows of one flow to <FlowName>.txt
# ---------------------------------------------------------------------
function Save-Flow([string]$FlowName, $Subflows, [string]$Source) {
# Replace characters that are not allowed in Windows file names
$safe = [regex]::Replace($FlowName, '[\\/:*?"<>|]', '_')
$outFile = Join-Path $OutputFolder ($safe + '.txt')
# Blank line between subflows; convert line endings back to Windows CRLF
$content = (@($Subflows.Values) -join "`r`n`r`n") -replace "(?<!`r)`n", "`r`n"
# Write as UTF-8 without BOM
[System.IO.File]::WriteAllText($outFile, $content, (New-Object System.Text.UTF8Encoding($false)))
# Record the result in the log and the summary
$line = 'OK | ' + $FlowName + ' | ' + $Subflows.Count + ' subflows (' + (@($Subflows.Keys) -join ', ') + ') | ' + $outFile
Write-Log ($line + ' | source: ' + $Source)
$Summary.Add($line)
}
# =====================================================================
# Main logic
# =====================================================================
try {
Write-Log ('Start. Source: ' + $SolutionPath)
# 1. Collect solution .zip files (a single file or every .zip in the folder)
if (Test-Path $SolutionPath -PathType Leaf) {
$Zips = @(Get-Item $SolutionPath)
} elseif (Test-Path $SolutionPath -PathType Container) {
$Zips = @(Get-ChildItem -Path $SolutionPath -File -Filter '*.zip')
} else {
throw ('Solution path not found: ' + $SolutionPath)
}
if ($Zips.Count -eq 0) { throw ('No solution .zip found in ' + $SolutionPath) }
foreach ($zip in $Zips) {
# 2. Unzip each solution into its own temp sub-folder
$root = Join-Path $WorkRoot $zip.BaseName
[System.IO.Compression.ZipFile]::ExtractToDirectory($zip.FullName, $root)
Write-Log ('Unzipped ' + $zip.Name)
# 3. Read customizations.xml and find every desktop flow (Workflow Category 6)
$custPath = Join-Path $root 'customizations.xml'
if (-not (Test-Path $custPath)) {
$Summary.Add('SKIP | ' + $zip.Name + ' | customizations.xml not found (not a solution export?)')
continue
}
[xml]$cx = Get-Content -Path $custPath -Raw -Encoding UTF8
$desktopFlows = @($cx.SelectNodes('//Workflow') | Where-Object { [string]$_.Category -eq '6' })
$Summary.Add('SOLUTION | ' + $zip.Name + ' | desktop flows found: ' + $desktopFlows.Count)
Write-Log ('Desktop flows found: ' + $desktopFlows.Count)
# Track names so two flows with the same name do not overwrite each other
$usedNames = @{}
foreach ($wf in $desktopFlows) {
$flowName = [string]$wf.Name
$flowId = ([string]$wf.WorkflowId).Trim('{', '}').ToLower()
if ($usedNames.ContainsKey($flowName)) { $flowName = $flowName + '_' + $flowId.Substring(0, 8) }
$usedNames[$flowName] = 1
# 4a. v2 schema: the script is in this flow's own <Definition> element
$script = ''
$defNode = $wf.SelectSingleNode('Definition')
if ($defNode -and $defNode.InnerText.Trim()) {
$script = Get-DefinitionText $defNode.InnerText
$src = 'customizations.xml <Definition>'
}
# 4b. Fallback (older exports): search the extracted files that belong
# to this flow - flow GUID in the path, or a desktopflowbinary.xml
# next to the file that references the flow GUID
if (-not $script) {
$parts = New-Object System.Collections.Generic.List[string]
foreach ($f in Get-ChildItem -Path $root -Recurse -File) {
$belongs = $f.FullName.ToLower().Contains($flowId)
$binXml = ''
if ($f.Directory.Parent) { $binXml = Join-Path $f.Directory.Parent.FullName 'desktopflowbinary.xml' }
if (-not $belongs -and $binXml -and (Test-Path $binXml)) {
$belongs = ((Get-Content $binXml -Raw) -match [regex]::Escape($flowId))
}
# Only text-type files that actually contain flow code
if ($belongs -and $f.Extension -in @('.json', '.xml', '.txt', '.robin')) {
$t = [System.IO.File]::ReadAllText($f.FullName)
if ($t -match 'FUNCTION') {
# Unescape up to 3 times in case the script is JSON-escaped more than once
$u = $t
for ($i = 0; $i -lt 3 -and $u -match '\\n|\\r'; $i++) { $u = ConvertFrom-JsonEscaped $u }
$parts.Add(($u -replace "`r`n", "`n"))
}
}
}
$script = $parts -join "`n"
$src = 'flow files'
}
# Nothing found for this flow - note it and move on
if (-not $script.Trim()) {
$Summary.Add('EMPTY | ' + $flowName + ' | no code found in export')
Write-Log ('No code found for ' + $flowName)
continue
}
# 5. Split into Main + subflows and save to <FlowName>.txt
$subflows = Split-RobinScript $script
Save-Flow $flowName $subflows $src
}
}
Write-Log 'Completed.'
} catch {
# Any error: write it to the log and the summary
Write-Log ('ERROR: ' + $_.Exception.Message)
$Summary.Add('ERROR | ' + $_.Exception.Message)
} finally {
# Always clean up the temporary unzip folder
Remove-Item -Path $WorkRoot -Recurse -Force -ErrorAction SilentlyContinue
}
# 6. Print the summary to the console
$Summary.Add('Log: ' + $LogFile)
Write-Output ($Summary -join "`r`n")





