Skip to content

Instantly share code, notes, and snippets.

@garrytrinder
Last active May 28, 2024 10:15
Show Gist options
  • Save garrytrinder/2f860630b8ef3945954ca922cb99cefc to your computer and use it in GitHub Desktop.
Save garrytrinder/2f860630b8ef3945954ca922cb99cefc to your computer and use it in GitHub Desktop.
Exports all Power Automate Flows as ZIP files from the default environment using CLI for Microsoft 365
Write-Output "Getting environment info..."
$environment = m365 flow environment list --query '[?contains(displayName,`default`)] .name'
Write-Output "Getting Flows info..."
$flows = m365 flow list --environment $environment --asAdmin --output json | ConvertFrom-JSON
Write-Output "Found $($flows.Count) Flows to export..."
$flows | ForEach-Object {
Write-Output "Exporting as ZIP & JSON... $($_.displayName)"
$filename = $_.displayName.Replace(" ","")
$timestamp = Get-Date -Format "yyyymmddhhmmss"
$exportPath = "$($filename)_$($timestamp)"
$flowId = $_.Name
m365 flow export --id $flowId --environment $environment --packageDisplayName $_.displayName --path "$exportPath.zip"
m365 flow export --id $flowId --environment $environment --format json --path "$exportPath.json"
}
Write-Output "Complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment