In Power Platform, solution deployments can sometimes introduce unexpected issues. Rolling back a solution deployment ensures stability in the environment by either reverting to a previous version or removing the faulty solution. Using PowerShell, you can automate this rollback process efficiently.
Step 1: Prerequisites
1.1 Install Required PowerShell Modules
Ensure the Power Platform PowerShell modules are installed:
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force
Install-Module -Name Microsoft.PowerApps.PowerShell -Force
1.2 Authenticate to Power Platform
Sign in to Power Platform using:
Add-PowerAppsAccount
1.3 Identify the Environment and Solution
Retrieve the environment name where the rollback needs to be performed:
Get-AdminPowerAppEnvironment | Select-Object DisplayName, EnvironmentName
Example Output:
DisplayName EnvironmentName
------------ -----------------------------
ProductionEnv fedcba98-7654-3210-fedc-ba9876543210
Check available solutions in the environment:
Get-CrmSolutions -EnvironmentName "fedcba98-7654-3210-fedc-ba9876543210"
Example Output:
FriendlyName UniqueName Version
------------- ------------ ---------
MySolution MySolution 1.0.0.2
MySolution MySolution 1.0.0.1
Step 2: Rolling Back to a Previous Version
If a new managed solution version is causing issues, rollback by re-importing the previous version.
2.1 Export the Previous Version Before Deployment
Before deploying an update, always keep a backup copy of the previous version:
$envName = "fedcba98-7654-3210-fedc-ba9876543210"
$solutionName = "MySolution"
$backupPath = "C:\Solutions\Backup\$solutionName-1.0.0.1.zip"
Export-CrmSolution -SolutionName $solutionName -Managed -OutFile $backupPath -EnvironmentName $envName
Write-Host "Backup of version 1.0.0.1 created."
2.2 Remove the Faulty Version
To remove the problematic version:
Remove-CrmSolution -SolutionName "MySolution" -EnvironmentName "fedcba98-7654-3210-fedc-ba9876543210"
Write-Host "Solution 'MySolution' removed."
2.3 Re-Import the Previous Version
Re-import the previous stable version:
$previousSolutionPath = "C:\Solutions\Backup\MySolution-1.0.0.1.zip"
Import-CrmSolution -SolutionFilePath $previousSolutionPath -EnvironmentName "fedcba98-7654-3210-fedc-ba9876543210" -ImportMode "Upgrade"
Write-Host "Solution rolled back to version 1.0.0.1."
Step 3: Rolling Back by Restoring a Backup
If a solution update causes critical failures, restore the entire environment backup.
3.1 Retrieve Available Backups
Check for available backups using:
Get-AdminPowerAppEnvironmentBackups -EnvironmentName "fedcba98-7654-3210-fedc-ba9876543210"
Example Output:
BackupId CreatedOn
-------- -------------------
12345678-abcd-4321-efgh-87654321abcd 2025-03-20 12:00
3.2 Restore a Backup
Restore-AdminPowerAppEnvironment -EnvironmentName "fedcba98-7654-3210-fedc-ba9876543210" -BackupId "12345678-abcd-4321-efgh-87654321abcd"
Write-Host "Environment restored to backup taken on 2025-03-20."
This may take some time, depending on the environment size.
Step 4: Automating Solution Rollback
4.1 PowerShell Script for Automated Rollback
Save the following script as Rollback-Solution.ps1
:
param (
[string]$envName = "fedcba98-7654-3210-fedc-ba9876543210",
[string]$solutionName = "MySolution",
[string]$backupPath = "C:\Solutions\Backup\$solutionName-1.0.0.1.zip"
)
# Authenticate
Add-PowerAppsAccount
# Remove Current Solution
Remove-CrmSolution -SolutionName $solutionName -EnvironmentName $envName
Write-Host "Solution '$solutionName' removed."
# Restore Previous Version
Import-CrmSolution -SolutionFilePath $backupPath -EnvironmentName $envName -ImportMode "Upgrade"
Write-Host "Solution '$solutionName' rolled back successfully."
Run this script:
powershell.exe -File "C:\Scripts\Rollback-Solution.ps1"
Step 5: Verifying the Rollback
Check the current solution version after rollback:
Get-CrmSolutions -EnvironmentName "fedcba98-7654-3210-fedc-ba9876543210" | Where-Object {$_.UniqueName -eq "MySolution"}
Expected Output:
FriendlyName UniqueName Version
------------- ------------ ---------
MySolution MySolution 1.0.0.1