Skip to content

Instantly share code, notes, and snippets.

@alirobe
Last active August 14, 2025 01:26
Show Gist options
  • Select an option

  • Save alirobe/17864cb8336ea9dc3d4da61fb5d6a596 to your computer and use it in GitHub Desktop.

Select an option

Save alirobe/17864cb8336ea9dc3d4da61fb5d6a596 to your computer and use it in GitHub Desktop.

Revisions

  1. alirobe revised this gist Aug 14, 2025. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion backup-dataverse-environment-solutions
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    # Import Solutions from Dataverse
    # Backup Solutions from Dataverse Environment
    # https://gist.github.com/alirobe/17864cb8336ea9dc3d4da61fb5d6a596

    ### Settings ###
    $skipExisting = $false # change to $true to update
  2. alirobe renamed this gist Aug 14, 2025. 1 changed file with 0 additions and 0 deletions.
  3. alirobe revised this gist Aug 14, 2025. No changes.
  4. alirobe renamed this gist Aug 14, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. alirobe created this gist Aug 14, 2025.
    46 changes: 46 additions & 0 deletions import.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # Import Solutions from Dataverse

    ### Settings ###
    $skipExisting = $false # change to $true to update

    ### Script ###
    $solutionsList = pac solution list
    $solutionsList > solutions-list.txt
    $firstLine = 5 # to be changed if output from pac tool changes
    $existing = Get-ChildItem -Path . -Directory
    $extracted = @()

    if ($solutionsList.Count -lt 5 -or -not $solutionsList[4].StartsWith("Unique Name")) {
    Write-Host "Unexpected output format. Ensure you are connected to the correct Dataverse organization and the solutions list is formatted correctly."
    }

    foreach ($line in $solutionsList[$firstLine..999]) {
    $solution = $line -split ' ' | Select-Object -First 1
    if($line.Trim().EndsWith("True") -or $solution -eq "Default") {
    Write-Host "Skipping managed or default solution: $solution"
    continue
    }
    if ($solution -eq $null -or $solution.Trim() -eq "" -or -not $line.Trim().EndsWith("False")) {
    Write-Host "Skipping invalid solution definition in line: $line"
    continue
    }
    if($existing.Name -contains $solution) {
    if($skipExisting) {
    Write-Host "Skipping existing solution: $solution (turn off skipExisting to updae)"
    continue
    } else {
    Write-Host "Removing existing solution for update: $solution"
    Remove-Item -Path ./$solution -Recurse -Force
    }
    }
    Write-Host "Processing solution: $solution"
    pac solution export --name $solution
    Expand-Archive -Path "$solution.zip" -DestinationPath ./$solution
    $extracted += "./$solution.zip"
    }

    foreach ($zip in $extracted) {
    Write-Host "Cleaning up zip: $zip"
    Start-Sleep -Seconds 2 # expansion can sometimes exit prematurely
    Remove-Item -Path $zip
    }