Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new command Export-PnPPowerApp #2990

Merged
merged 11 commits into from
Jul 17, 2023
198 changes: 198 additions & 0 deletions documentation/Export-PnPPowerApp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Export-PnPPowerApp.html
external help file: PnP.PowerShell.dll-Help.xml
title: Export-PnPPowerApp
---

# Export-PnPPowerApp

## SYNOPSIS

**Required Permissions**

* Azure: management.azure.com

Exports a Microsoft Power App

## SYNTAX

```
Export-PnPPowerApp -Environment <PowerPlatformEnvironmentPipeBind> -Identity <PowerAppPipeBind>
[-PackageDisplayName <String>] [-PackageDescription <String>] [-PackageCreatedBy <String>]
[-PackageSourceEnvironment <String>] [-OutPath <String>] [-Force] [-Connection <PnPConnection>]
[<CommonParameters>]
```

## DESCRIPTION
This cmdlet exports a Microsoft Power App as zip package.

Many times exporting a Microsoft Power App 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 App. To display these errors when trying to export a App, provide the -Verbose flag with your export request. If not provided, these errors will silently be ignored.

## EXAMPLES

### Example 1
```powershell
$environment = Get-PnPPowerPlatformEnvironment -IsDefault $true
Export-PnPPowerApp -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -OutPath "C:\Users\user1\Downloads\test_20230408152624.zip"
```

This will export the specified Microsoft Power App from the default Power Platform environment as an output to the path specified in the command as -OutPath

### Example 2
```powershell
$environment = Get-PnPPowerPlatformEnvironment -IsDefault $true
Export-PnPPowerApp -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -OutPath "C:\Users\user1\Downloads\test_20230408152624.zip" -PackageDisplayName "MyAppDisplayName" -PackageDescription "Package exported using PnP Powershell" -PackageCreatedBy "Siddharth Vaghasia" -PackageSourceEnvironment "UAT Environment"
```
This will export the specified Microsoft Power App from the default Power Platform environment with metadata specified

### Example 3
```powershell
Get-PnPPowerPlatformEnvironment | foreach { Get-PnPPowerApp -Environment $_.Name } | foreach { Export-PnPPowerApp -Environment $_.Properties.EnvironmentDetails.Name -Identity $_ -OutPath "C:\Users\user1\Downloads\$($_.Name).zip" }
```

This will export all the Microsoft Power Apps available within the tenant from all users from all the available Power Platform environments as a ZIP package for each of them to a local folder C:\Users\user1\Downloads

## 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 environment which contains the App.

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

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

### -Identity
The value of the Name property of a Microsoft Power App that you wish to export

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

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

### -Force
If specified and the file exported already exists it will be overwritten without confirmation.

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

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

### -OutPath
Optional file name of the file to export to. If not provided, it will store the ZIP package to the current location from where the cmdlet is being run.

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

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

### -PackageCreatedBy
The name of the person to be used as the creator of the exported package

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

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

### -PackageDescription
The description to use in the exported package

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

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

### -PackageDisplayName
The display name to use in the exported package

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

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

### -PackageSourceEnvironment
The name of the source environment from which the exported package was taken

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

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

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp.Enums
{
/// <summary>
/// Contains the possible states of a App export request
/// </summary>
public enum PowerAppExportStatus
{
/// <summary>
/// PowerApp export failed
/// </summary>
Failed,

/// <summary>
/// PowerApp exported successfully
/// </summary>
Succeeded,

/// <summary>
/// Export in progress
/// </summary>
Running
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp
{
/// <summary>
/// Contains the error details when requesting an export of a Flow package
/// </summary>
public class PowerAppExportPackageError
{
/// <summary>
/// Error code
/// </summary>
[JsonPropertyName("code")]
public string Code { get; set; }

/// <summary>
/// Description of the error
/// </summary>
[JsonPropertyName("message")]
public string Message { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp
{
/// <summary>
/// Contains details on a specific resource in a Flow export request
/// </summary>
public class PowerAppExportPackageResource
{
/// <summary>
/// Full identifier path of the resource
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
/// Identifier of the resource
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>
/// Type of resource
/// </summary>
[JsonPropertyName("type")]
public string Type { get; set; }

/// <summary>
/// Indicator if the resource should be updated or considered a new resource by default on import
/// </summary>
[JsonPropertyName("creationType")]
public string CreationType { get; set; }

/// <summary>
/// Additional details on the resource
/// </summary>
[JsonPropertyName("details")]
public Dictionary<string, string> Details { get; set; }

/// <summary>
/// Indicator who can configure the resource
/// </summary>
[JsonPropertyName("configurableBy")]
public string ConfigurableBy { get; set; }

/// <summary>
/// Indicator where this resource is located in a hierarchical structure
/// </summary>
[JsonPropertyName("hierarchy")]
public string Hierarchy { get; set; }

/// <summary>
/// Indicator if there are dependencies on other resources
/// </summary>
[JsonPropertyName("dependsOn")]
public object[] DependsOn { get; set; }

/// <summary>
/// Suggested approach on import
/// </summary>
[JsonPropertyName("suggestedCreationType")]
public string SuggestedCreationType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp
{
/// <summary>
/// Contains the results of a request to export a Flow package
/// </summary>
public class PowerAppPackageWrapper
{
/// <summary>
/// Raw state indicating if the Flow export request was successful
/// </summary>
[JsonPropertyName("status")]
public string StatusRaw { get; set; }

/// <summary>
/// The status of the export request as an enum
/// </summary>
[JsonIgnore]
public Enums.PowerAppExportStatus? Status
{
get { return !string.IsNullOrWhiteSpace(StatusRaw) && Enum.TryParse<Enums.PowerAppExportStatus>(StatusRaw, true, out var result) ? result : (Enums.PowerAppExportStatus?)null; }
set { StatusRaw = value.ToString(); }
}

/// <summary>
/// Contains the resource identifiers
/// </summary>
[JsonPropertyName("baseResourceIds")]
public string[] BaseResourceIds { get; set; }

/// <summary>
/// List with resources contained in the export
/// </summary>
[JsonPropertyName("resources")]
public Dictionary<string, PowerAppExportPackageResource> Resources { get; set; }

/// <summary>
/// Array with errors generated when trying to export the resource
/// </summary>
[JsonPropertyName("errors")]
public PowerAppExportPackageError[] Errors{ get; set; }
}
}
Loading
Loading