Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions documentation/Import-PnPFlow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Import-PnPFlow.html
external help file: PnP.PowerShell.dll-Help.xml
title: Import-PnPFlow
---

# Import-PnPFlow

## SYNOPSIS

**Required Permissions**

* Azure: management.azure.com

Imports a Microsoft Power Automate Flow.

## SYNTAX

### With Zip Package
```powershell
Import-PnPFlow [-Environment <PowerAutomateEnvironmentPipeBind>] [-PackagePath <String>] [-Name <String>] [-Connection <PnPConnection>]

```

## DESCRIPTION
This cmdlet imports a Microsoft Power Automate Flow from a ZIP package. At present, only flows originating from the same tenant are supported.

Many times Importing a Microsoft Power Automate Flow will not be possible due to various reasons such as connections having gone stale, SharePoint sites referenced no longer existing or other configuration errors in the Flow. To display these errors when trying to Import a Flow, provide the -Verbose flag with your Import request. If not provided, these errors will silently be ignored.

## EXAMPLES

### Example 1
```powershell
Import-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName
```

This will Import the specified Microsoft Power Automate Flow from the specified Power Platform environment as an output to the current output of PowerShell

### Example 2
```powershell
Import-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName
```

This will Import the specified Microsoft Power Automate Flow from the default Power Platform environment as an output to the current output of PowerShell

### Example 3
```powershell
Import-PnPFlow -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName
```

This will Import a flow to the default environment. The flow will be imported as a zip package. The name of the flow will be set to NewFlowName.

### Example 4
```powershell
Import-PnPFlow -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName -Verbose
```

This will Import a flow to the default environment. The flow will be imported as a zip package. The name of the flow will be set to NewFlowName. With the -Verbose flag, any errors that occur during the import process will be displayed in the console.

## PARAMETERS

### -Connection
Optional connection to be used by the cmdlet.
Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

```yaml
Type: PnPConnection
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Environment
The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used.

```yaml
Type: PowerPlatformEnvironmentPipeBind
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: The default environment
Accept pipeline input: True
Accept wildcard characters: False
```

### -PackagePath
Local path of the .zip package to import. The path must be a valid path on the local file system.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: true
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Name
The new name of the flow.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: true
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
22 changes: 22 additions & 0 deletions src/Commands/Model/PowerPlatform/PowerAutomate/ImportFlowResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate
{
public class ImportFlowResult
{
public string Name { get; set; }
public string Status { get; set; }
public ImportFlowDetails Details { get; set; }
}

public class ImportFlowDetails
{
public string DisplayName { get; set; }
public string Description { get; set; }
public DateTime CreatedTime { get; set; }
}
}
44 changes: 44 additions & 0 deletions src/Commands/PowerPlatform/PowerAutomate/ImportFlow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Utilities;
using System.Management.Automation;


namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate
{
[Cmdlet(VerbsData.Import, "PnPFlow")]
[ApiNotAvailableUnderApplicationPermissions]
[RequiredApiDelegatedPermissions("azure/user_impersonation")]
public class ImportFlow : PnPAzureManagementApiCmdlet
{
private const string ParameterSet_BYIDENTITY = "By Identity";
private const string ParameterSet_ALL = "All";

[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_BYIDENTITY)]
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_ALL)]
[Parameter(Mandatory = false)]
public PowerPlatformEnvironmentPipeBind Environment;

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_ALL)]
public string PackagePath;

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_ALL)]
public string Name;

protected override void ExecuteCmdlet()
{
var environmentName = GetEnvironmentName();
string baseUrl = PowerPlatformUtility.GetBapEndpoint(Connection.AzureEnvironment);
var importStatus = ImportFlowUtility.ExecuteImportFlow(Connection.HttpClient,AccessToken,baseUrl,environmentName,PackagePath,Name);
WriteObject(importStatus);
}

private string GetEnvironmentName()
{
return ParameterSpecified(nameof(Environment))
? Environment.GetName()
: PowerPlatformUtility.GetDefaultEnvironment(ArmRequestHelper, Connection.AzureEnvironment)?.Name;
}
}
}
Loading
Loading