Exporting a Power App as a Package using PowerShell

Loading

Exporting a Power App as a package using PowerShell allows administrators to back up, transfer, or deploy apps across environments efficiently. This process ensures proper app lifecycle management in Microsoft Power Platform.


Step 1: Install Required PowerShell Modules

Ensure that you have the necessary PowerShell modules installed:

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -AllowClobber
Install-Module -Name Microsoft.PowerApps.PowerShell -Force -AllowClobber

If prompted, press Y to confirm installation.


Step 2: Authenticate to Power Platform

Log in using an Admin account:

Add-PowerAppsAccount

For service principal authentication:

$clientId = "your-client-id"
$clientSecret = "your-client-secret"
$tenantId = "your-tenant-id"

$SecureSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($clientId, $SecureSecret)

Connect-AdminPowerAppEnvironment -TenantId $tenantId -Credential $Credential

Step 3: Retrieve Available Power Apps

List all Power Apps in a specific environment:

$environmentId = "your-environment-id"

Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, CreatedTime, LastModifiedTime

Identify the AppName of the app you want to export.


Step 4: Export the Power App as a Package

Use the Export-AdminPowerAppPackage command to export the Power App as a package:

$appId = "your-app-id"
$environmentId = "your-environment-id"
$outputPath = "C:\PowerPlatform\PowerAppPackage.zip"

Export-AdminPowerAppPackage -AppName $appId -EnvironmentName $environmentId -PackageOutputPath $outputPath

This command will save the Power App package as a ZIP file at the specified path.


Step 5: Verify the Exported Package

Navigate to the export location:

explorer C:\PowerPlatform\

You should see a PowerAppPackage.zip file.


Step 6: Exporting Power App Details to a CSV (Optional)

For tracking purposes, export Power App details to a CSV file:

$exportPath = "C:\PowerPlatform\ExportedApps.csv"

Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, CreatedTime, LastModifiedTime |
Export-Csv -Path $exportPath -NoTypeInformation

This will save a list of exported apps to C:\PowerPlatform\ExportedApps.csv.


Step 7: Disconnect from Power Platform

Once done, disconnect the session:

Disconnect-PowerAppsAccount

Leave a Reply

Your email address will not be published. Required fields are marked *