PAC CLI Advanced Commands

Loading


The Power Platform Command Line Interface (PAC CLI) is a powerful tool that enables developers and administrators to interact with Microsoft Power Platform directly from the command line. While beginners often start with simple commands for authentication or solution export, advanced PAC CLI commands offer much more—from ALM automation and environment management to data operations, solution checking, and code generation.

This article provides a deep dive into PAC CLI’s advanced features and commands, explores use cases for power users, and outlines best practices for integrating PAC CLI into modern DevOps pipelines.


What is PAC CLI?

PAC CLI is a cross-platform command-line interface provided by Microsoft that allows users to manage Power Platform components and environments programmatically. It enables interaction with:

  • Solutions
  • Dataverse
  • Environment administration
  • Power Apps portals
  • ALM pipelines
  • Code generation

PAC CLI is especially valuable for professional developers, DevOps engineers, and advanced Power Platform administrators looking to automate tasks or integrate Power Platform into a larger CI/CD pipeline.


Getting Started

Before diving into advanced commands, you should install and authenticate PAC CLI:

pac install latest
pac auth create --url https://yourenv.crm.dynamics.com

Use pac help to see available command categories. Once familiar with basic commands, let’s explore the advanced features.


1. Advanced Solution Management

a. Export with Parameters

To export a solution with all dependent components, managed format, and a unique version tag:

pac solution export --name "ContosoApp" --path "./out/ContosoApp.zip" --managed --targetversion "1.0.0.25"

b. Pack and Unpack Solutions for Source Control

Source-control friendly solutions are critical for ALM. Use these commands to decompose and reassemble solutions:

Unpack:

pac solution unpack --zipfile "./ContosoApp.zip" --folder "./solutions/ContosoApp" --allowDelete

Pack:

pac solution pack --folder "./solutions/ContosoApp" --zipfile "./out/ContosoApp.zip" --packagetype Managed

This enables tracking solution files like plugins, workflows, and web resources in Git.


2. Automate ALM with Solution Checker

Solution Checker provides static analysis of your code, identifying performance or security issues.

pac solution checker --path "./solutions/ContosoApp"

Output as SARIF for DevOps Integration

For integration with GitHub or Azure DevOps:

pac solution checker --path "./solutions/ContosoApp" --outputSarif ./results/contoso_sarif.json

This enables code scanning alerts and visibility directly in PRs or pipeline dashboards.


3. Environment Management

PAC CLI supports advanced environment commands:

a. List Environments

pac admin list

b. Create a New Environment (Developer or Sandbox)

pac admin create --name "contoso-dev" --type Sandbox --region "us"

c. Backup and Restore Environments

Backup:

pac admin backup --environment "contoso-dev"

Restore:

pac admin restore --environment "contoso-dev" --backupid "GUID-of-backup"

These operations are critical during testing, pre-deployment snapshots, or recovery.


4. Dataverse Data Management

Advanced users can use pac data to manage reference data in solutions:

a. Export Data

pac data export --environment "contoso-dev" --schemafile "./schema.json" --datafile "./data.zip"

b. Import Data

pac data import --environment "contoso-test" --datafile "./data.zip"

This is useful for:

  • Migrating reference data
  • Testing with seed data
  • Replicating datasets across environments

5. Authentication Scenarios

Advanced scenarios may involve switching between environments, using non-interactive service principal authentication, or scripting login.

a. Multiple Authentication Profiles

pac auth list
pac auth select --index 2

b. Service Principal Auth for Automation

pac auth create --url https://yourenv.crm.dynamics.com --clientId <app-id> --clientSecret <secret> --tenant <tenant-id>

This is ideal for CI/CD pipelines that require headless access to Power Platform environments.


6. Custom Connector Lifecycle

Create, deploy, and update custom connectors via PAC CLI:

a. Create a Connector from an OpenAPI file

pac connector create --environment "contoso-dev" --name "MyAPI" --openApiSpec "./myapi.json"

b. Update an Existing Connector

pac connector update --environment "contoso-dev" --connectorId "GUID" --openApiSpec "./updated_api.json"

This allows connectors to be fully version-controlled and deployed programmatically.


7. Power Pages (Portals) Management

PAC CLI offers commands under the pac paportal namespace for managing portal content.

a. Download Portal Content

pac paportal download --path ./portal/ --websiteId <website-guid>

b. Upload Changes Back to Portal

pac paportal upload --path ./portal/

c. Useful for:

  • Source-controlling portal configuration
  • Automating deployment
  • Creating content deployment pipelines for Power Pages

8. Plugin and Code Generation

Generate early-bound classes or plugin templates:

a. Generate Early-Bound Classes

pac modelbuilder build --serviceUri https://yourenv.crm.dynamics.com --out "./Models"

b. Create a Plugin Skeleton

pac plugin init --name "AccountUpdatePlugin" --namespace "Contoso.Plugins"

This improves developer productivity by scaffolding boilerplate code.


9. Packaging and Deployment Pipelines

Integrate PAC CLI into your DevOps workflows using YAML pipelines in Azure DevOps or GitHub Actions.

Azure DevOps Example:

- task: PowerPlatformToolInstaller@0
- task: PowerPlatformExportSolution@0
  inputs:
    solutionName: 'ContosoApp'
    solutionOutputFile: '$(Build.ArtifactStagingDirectory)/ContosoApp.zip'

- task: PowerPlatformChecker@0
  inputs:
    solutionInputFile: '$(Build.ArtifactStagingDirectory)/ContosoApp.zip'

GitHub Actions Example:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: microsoft/powerplatform-actions/actions/authenticate@v1
      with:
        app-id: ${{ secrets.CLIENT_ID }}
        client-secret: ${{ secrets.CLIENT_SECRET }}
        tenant-id: ${{ secrets.TENANT_ID }}
        environment-url: ${{ secrets.ENV_URL }}
    - uses: microsoft/powerplatform-actions/actions/solution-export@v1
      with:
        solution-name: 'ContosoApp'
        output-folder: './solutions'

10. Best Practices for PAC CLI Power Users

✅ Use Scripts for Repeatability

Write shell or PowerShell scripts that combine PAC CLI commands for repeatable and consistent deployments.

✅ Use Environment Variables

Avoid hardcoding credentials. Use environment variables or secure pipeline secrets for sensitive data like client secrets.

✅ Integrate with Source Control

Decompose solutions, portals, and data into structured folders and store them in Git for proper version control and change tracking.

✅ Combine with ALM Accelerator

Use PAC CLI alongside Microsoft’s ALM Accelerator for Power Platform to manage environment strategy, pull requests, and deployments.

✅ Keep CLI Up-to-Date

New features and fixes are added frequently. Run:

pac install latest

To ensure you’re using the latest capabilities.


11. Troubleshooting and Debugging

Use --verbose or --debug flags for detailed output:

pac solution import --path "./ContosoApp.zip" --verbose

Check logs in %AppData%\Microsoft\PowerAppsCli for Windows or ~/.microsoft/pac on macOS/Linux.



Leave a Reply

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