Backup Power Platform Environment With PowerShell

In this first blog post on Power Platform, we will show you how to backup your environment using PowerShell.

Power Platform

If you are not familiar with Microsoft Power Platform, The Power Platform hosts several business applications like Power Apps, Power Automate, Power BI and Microsoft Dynamics.

Environment

A Power Platform environment hosts all the applications that are hosted on the Power Platform. In this post, we will use the Power Platform PowerShell module to connect and backup an environment.

In Power Platform, we can have multiple environments (PROD, Sandbox, Dev, etc.).

PowerShell

To get started, we first need to install the Power Platform PowerShell module. The module works on Windows machines only and runs on PowerShell 5.1 (No PowerShell core).

To install the module, Open your PowerShell terminal and run the following cmdlet.

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

Connect and Add Environment

Now we need to connect to the Power Platform using the following command.

Add-PowerAppsAccount -Endpoint prod

Get Environment ID

After connecting, we need to get the environment GUID using the following cmdlet.

Get-AdminPowerAppEnvironment | fl

Backup

Now that we are connected and have the environment ID, we can run a backup using the following code.

Save the code as a .PS1 file, paste the GUID of your environment, and run the script.

$backupRequest = [pscustomobject]@{
        Label = "PowerShell backup"
        Notes = "Backup"
}
   Backup-PowerAppEnvironment -EnvironmentName "GUID" -BackupRequestDefinition $backupRequest

To check if the backup was successful, run the following command.

$x = Get-PowerAppEnvironmentBackups -EnvironmentName "GUID" 

foreach ($item in $x.psobject.properties.value) {
   $item    
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.