Skip to content

Commit 585f952

Browse files
💡New command - Import-PnPFlow (#4854)
* Initial commit for New command - Import-PnPFlow * Test scenarios passed * Code refactored and added documentation * Refactoring ImportFlow * Final commit after refactoring and updating documentation --------- Co-authored-by: Gautam Sheth <[email protected]>
1 parent 26c27ab commit 585f952

File tree

4 files changed

+501
-0
lines changed

4 files changed

+501
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
schema: 2.0.0
4+
applicable: SharePoint Online
5+
online version: https://pnp.github.io/powershell/cmdlets/Import-PnPFlow.html
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
title: Import-PnPFlow
8+
---
9+
10+
# Import-PnPFlow
11+
12+
## SYNOPSIS
13+
14+
**Required Permissions**
15+
16+
* Azure: management.azure.com
17+
18+
Imports a Microsoft Power Automate Flow.
19+
20+
## SYNTAX
21+
22+
### With Zip Package
23+
```powershell
24+
Import-PnPFlow [-Environment <PowerAutomateEnvironmentPipeBind>] [-PackagePath <String>] [-Name <String>] [-Connection <PnPConnection>]
25+
26+
```
27+
28+
## DESCRIPTION
29+
This cmdlet imports a Microsoft Power Automate Flow from a ZIP package. At present, only flows originating from the same tenant are supported.
30+
31+
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.
32+
33+
## EXAMPLES
34+
35+
### Example 1
36+
```powershell
37+
Import-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName
38+
```
39+
40+
This will Import the specified Microsoft Power Automate Flow from the specified Power Platform environment as an output to the current output of PowerShell
41+
42+
### Example 2
43+
```powershell
44+
Import-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName
45+
```
46+
47+
This will Import the specified Microsoft Power Automate Flow from the default Power Platform environment as an output to the current output of PowerShell
48+
49+
### Example 3
50+
```powershell
51+
Import-PnPFlow -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName
52+
```
53+
54+
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.
55+
56+
### Example 4
57+
```powershell
58+
Import-PnPFlow -PackagePath C:\Temp\Export-ReEnableFlow_20250414140636.zip -Name NewFlowName -Verbose
59+
```
60+
61+
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.
62+
63+
## PARAMETERS
64+
65+
### -Connection
66+
Optional connection to be used by the cmdlet.
67+
Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.
68+
69+
```yaml
70+
Type: PnPConnection
71+
Parameter Sets: (All)
72+
Aliases:
73+
74+
Required: False
75+
Position: Named
76+
Default value: None
77+
Accept pipeline input: False
78+
Accept wildcard characters: False
79+
```
80+
81+
### -Environment
82+
The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used.
83+
84+
```yaml
85+
Type: PowerPlatformEnvironmentPipeBind
86+
Parameter Sets: (All)
87+
Aliases:
88+
89+
Required: False
90+
Position: Named
91+
Default value: The default environment
92+
Accept pipeline input: True
93+
Accept wildcard characters: False
94+
```
95+
96+
### -PackagePath
97+
Local path of the .zip package to import. The path must be a valid path on the local file system.
98+
99+
```yaml
100+
Type: String
101+
Parameter Sets: (All)
102+
Aliases:
103+
104+
Required: true
105+
Position: Named
106+
Default value: None
107+
Accept pipeline input: False
108+
Accept wildcard characters: False
109+
```
110+
111+
### -Name
112+
The new name of the flow.
113+
114+
```yaml
115+
Type: String
116+
Parameter Sets: (All)
117+
Aliases:
118+
119+
Required: true
120+
Position: Named
121+
Default value: None
122+
Accept pipeline input: False
123+
Accept wildcard characters: False
124+
```
125+
126+
## RELATED LINKS
127+
128+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate
8+
{
9+
public class ImportFlowResult
10+
{
11+
public string Name { get; set; }
12+
public string Status { get; set; }
13+
public ImportFlowDetails Details { get; set; }
14+
}
15+
16+
public class ImportFlowDetails
17+
{
18+
public string DisplayName { get; set; }
19+
public string Description { get; set; }
20+
public DateTime CreatedTime { get; set; }
21+
}
22+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using PnP.PowerShell.Commands.Attributes;
2+
using PnP.PowerShell.Commands.Base;
3+
using PnP.PowerShell.Commands.Base.PipeBinds;
4+
using PnP.PowerShell.Commands.Utilities;
5+
using System.Management.Automation;
6+
7+
8+
namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate
9+
{
10+
[Cmdlet(VerbsData.Import, "PnPFlow")]
11+
[ApiNotAvailableUnderApplicationPermissions]
12+
[RequiredApiDelegatedPermissions("azure/user_impersonation")]
13+
public class ImportFlow : PnPAzureManagementApiCmdlet
14+
{
15+
private const string ParameterSet_BYIDENTITY = "By Identity";
16+
private const string ParameterSet_ALL = "All";
17+
18+
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_BYIDENTITY)]
19+
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_ALL)]
20+
[Parameter(Mandatory = false)]
21+
public PowerPlatformEnvironmentPipeBind Environment;
22+
23+
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_ALL)]
24+
public string PackagePath;
25+
26+
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_ALL)]
27+
public string Name;
28+
29+
protected override void ExecuteCmdlet()
30+
{
31+
var environmentName = GetEnvironmentName();
32+
string baseUrl = PowerPlatformUtility.GetBapEndpoint(Connection.AzureEnvironment);
33+
var importStatus = ImportFlowUtility.ExecuteImportFlow(Connection.HttpClient,AccessToken,baseUrl,environmentName,PackagePath,Name);
34+
WriteObject(importStatus);
35+
}
36+
37+
private string GetEnvironmentName()
38+
{
39+
return ParameterSpecified(nameof(Environment))
40+
? Environment.GetName()
41+
: PowerPlatformUtility.GetDefaultEnvironment(ArmRequestHelper, Connection.AzureEnvironment)?.Name;
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)