Tracking Solution Version History in Power Platform using PowerShell

Loading

Tracking solution version history in Microsoft Power Platform is crucial for auditability, rollback, and deployment tracking. With PowerShell, you can:
✔ Retrieve current solution version
✔ Maintain a version history log
✔ Automate version tracking before deployments


Step 1: Prerequisites

1.1 Install Power Platform PowerShell Modules

Ensure the necessary 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

Log in to Power Platform using:

Add-PowerAppsAccount

1.3 Identify Available Environments

Run the following command to list environments and note down the Environment ID:

Get-AdminPowerAppEnvironment

Step 2: Retrieving Solution Version

To check the current version of a solution, run:

$solutionName = "YourSolutionName"
$environmentName = "YourEnvironmentID"

Get-CrmSolution -EnvironmentName $environmentName -SolutionName $solutionName | Select-Object SolutionName, Version

Output Example:

SolutionName   Version
------------- --------
MySolution 1.0.0.3

Step 3: Maintaining a Version History Log

3.1 Define Log File Path

Create a log file to store version history:

$logFile = "C:\PowerPlatform\SolutionVersionHistory.csv"

3.2 Append Version History

Modify the script to log version history:

$solutionInfo = Get-CrmSolution -EnvironmentName $environmentName -SolutionName $solutionName | Select-Object SolutionName, Version
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

$logEntry = "$timestamp,$($solutionInfo.SolutionName),$($solutionInfo.Version)"
Add-Content -Path $logFile -Value $logEntry

This appends the solution version to SolutionVersionHistory.csv.


Step 4: Automating Version Tracking Before Deployment

4.1 Full Automation Script (Track-SolutionVersion.ps1)

param (
[string]$solutionName = "YourSolutionName",
[string]$environmentName = "YourEnvironmentID",
[string]$logFile = "C:\PowerPlatform\SolutionVersionHistory.csv"
)

# Get solution version
$solutionInfo = Get-CrmSolution -EnvironmentName $environmentName -SolutionName $solutionName | Select-Object SolutionName, Version
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

# Append to version log
$logEntry = "$timestamp,$($solutionInfo.SolutionName),$($solutionInfo.Version)"
Add-Content -Path $logFile -Value $logEntry

Write-Host "Solution version logged successfully: $logEntry"

4.2 Running the Script

Execute using:

.\Track-SolutionVersion.ps1 -solutionName "MySolution"

This script automatically logs version history before deployments.


Step 5: CI/CD Integration

To track solution versions in Azure DevOps, add this PowerShell task:

- task: PowerShell@2
inputs:
filePath: 'Track-SolutionVersion.ps1'
arguments: '-solutionName "MySolution"'

Version history is now automated across Dev, Test, and Prod.

Leave a Reply

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