Amazon.co.uk Widgets

Log in

X
PAC CLI

This article is about Getting started with the Power Platform / PowerApps command line interface (CLI). You might be wondering why no code or low code tools need a CLI but worry not because theres a completely clear explanation: "The Power Platform CLI (PowerApps CLI) works for both inner loop development and outer loop development. The inner loop is for when a developer wants to work on a project and build a new feature for instance. The outer loop is to make sure that what has been built, also can be deployed to other environments." I prefer to think of this as software development (Dev) and IT operations (Ops) and application lifecycle management (ALM). To me theres no separation of loop. I guess it might make sense for citizen developers / makers to be considered inner loop and pro developers to be outer loop but it seems a bit artificial.

Wait, what is the Power Platform CLI (PowerApps CLI)?

Seriously though, the Power Platform CLI is a vital set of utilities designed for developers with an emphasis on both single use and scriptability. 

  • Power Platform CLI is a single low level integration point for VSCodium (or VS Code), for GitHub Actions and for any other services that might benefit from scripting.
  • Power Platform CLI provides a proper GitHub first developer experience for the wider power platform including pages, components, connectors, solutions, packages, installers and more
  • Power Platform CLI uses the command line tool PAC with a wealth of administrative capabilities previously only accessible from the Power Apps Admin web console.

Installing the Power Platform CLI (PowerApps CLI)

Microsoft point out the easiest way to use the CLI is to install it as a platform extension in VSCode. You can also install it for macOS and Linux although some funcitonality which depends on the Windows version of the .net framework will not function.

Installing PowerApps CLI on Windows 11

  • Find and run the MSI installer for Windows https://aka.ms/PowerAppsCLI. The installer calls itself the PowerApps CLI so that is the term I will use from now on although Microsoft use Power Platform CLI.
    PowerApps CLI installer
    The PowerApps CLI installer
  • Let it finish, it will open a terminal to do its thing. 
  • And then check it is working by running it

Installing PowerApps CLI on macOS Ventura via VSCodium (or VS Code)

Install .NET for macOS

You can use .NET as part of a continuous integration, continuous development (CI/CD) workflow with GitHub because GitHub hosted runners are preinstalled with .NET Core SDK amongst the list of software tools they provide for GitHub Actions to use. This is something I didn't know, and I also didn't know that .NET runs on macOS, and even on Apple silicon equipped Mac computers. For CI/CD with PowerApps thats going to be important, and for me its important it works on a Mac.

% dotnet tool install --global Microsoft.PowerApps.CLI.Tool

Welcome to .NET 7.0!
---------------------
SDK Version: 7.0.306

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
Tools directory '/Users/angusf/.dotnet/tools' is not currently on the PATH environment variable.
If you are using zsh, you can add it to your profile by running the following command:

cat << \EOF >> ~/.zprofile
# Add .NET Core SDK tools
export PATH="$PATH:/Users/angusf/.dotnet/tools"
EOF

And run `zsh -l` to make it available for current session.

You can only add it to the current session by running the following command:

export PATH="$PATH:/Users/angusf/.dotnet/tools"

You can invoke the tool using the following command: pac
Tool 'microsoft.powerapps.cli.tool' (version '1.25.3') was successfully installed.
  • Now you are ready to install the extension for VSCodium or VS Code.
  • You'll need to sideload the extension for VSCodium. Find the download link on the page and download it.
    Power Platform Tools from the marketplace
    Power Platform Tools from the marketplace
  • Launch VSCodium and select the Extensions icon, then select the more icon (ellipsis) on the Extensions side bar, and then select Install from VSIX.
    Install from VSIX... Menu item
    Install from VSIX... Menu item

Success in VSCodium / VS Code

You should see the results of a successful install in the VSCodium notifications. If you see an error, you either didnt get the .net installation right, or you didnt install the PAC tool properly and set the path to it for your command shell. 

See how it says the PAC CLI is ready for use!
See how it says the PAC CLI is ready for use!

Run the PAC CLI from the terminal inside VSCodium / VS Code

Now you can run the PAC CLI commands in the terminal inside VSCodium / VS Code
Now you can run the PAC CLI commands in the terminal inside VSCodium / VS Code

 

Getting started with the Power Platform CLI PAC commands

First thing to do is set the context for this user account by creating and storing authentication profiles for this user on this computer. Type % pac auth createin the Terminal in VSCodium / VS Code. It will load a default browser window for you to authenticate your Microsoft Sign in account.

Microsoft Online OAuth 2.0 Sign in screen
Microsoft Online OAuth 2.0 Sign in screen

Once you complete the OAuth Sign in dance, you'll see your profile has been created. Now you can use the PAC CLI to access your Power Platform.

% pac auth create
This email address is being protected from spambots. You need JavaScript enabled to view it.' authenticated successfully.
Validating connection...
Default organization: production-orgname
Authentication profile created
    * UNIVERSAL https://orgc0ffee01.crm11.dynamics.com/ : This email address is being protected from spambots. You need JavaScript enabled to view it. Public

By default this creates a profile for your username for the tenant and connects you to the default environment. 

Profile Stored locally

I wondered what happened to the profile information, since it must persist across machine reboots and it can't really be held in the Browser cache. I found it. It is stored in  ~/.local/share/Microsoft/PowerAppsCli. Heres part of mine. mine (details are not real).

{
  "Profiles": [
    {
      "Kind": "UNIVERSAL",
      "User": "This email address is being protected from spambots. You need JavaScript enabled to view it.",
      "AadObjectId": "46f2a44a-b8b5-4d16-83f2-695a38f46855",
      "Puid": null,
      "UserCountry": null,
      "Resource": "https://orgnnnnnnnn.crmnn.dynamics.com",
      "EnvironmentId": "6529b3bc-27d0-11ee-a201-2eb5a363657c",
      "EnvironmentType": "Default",
      "ExpiresOn": "2099-07-21T12:20:17.00459+00:00",
      "Authority": "https://login.microsoftonline.com/organizations",
      "Name": "",
      "ProfileType": 0,
      "CloudInstance": 0,
      "TenantId": "d69a6e6d-466c-42d2-a20b-8dd63dd12c68",
      "TenantCountry": null,
      "OrganizationUniqueName": null,
      "FriendlyName": "production-orgname"
    }
  ],
 ...
}%

When you run Pac Auth Create, this settings file is created. I couldnt find it documented anywhere so its clearly not meant to be edited outside of the PAC command line.

PAC Auth – Commands to connect to your environment.

Theres a set of associated commands for authentication profile management. Probably the only useful one at this point is pac auth list which confirms your profile settings.

The settings themselves are tucked away in a hidden folder in your home folder.

  • list — shows the authentication profiles stored on this computer
  • create — Create and store authentication profiles on this computer
  • select — Select which authentication profile should be active
  • delete — Delete a particular authentication profile
  • update — Update name or target environment of an existing authentication profile
  • name — Name or rename an existing authentication profile
  • clear — Clear all authentication profiles stored on this computer

PAC Org – Commands for working with Dataverse environments.

Theres a set of associated commands for authentication profile management. Probably the most useful one at this point is pac org list which lists all of the Dataverse organizations the user has access to.

The settings themselves are tucked away in a hidden folder in your home folder.

  • who — Displays information about the current Dataverse organization
    % pac org who
    Connected to... production-orgname
    Connected as This email address is being protected from spambots. You need JavaScript enabled to view it.
    Organization Information
      Org ID:                     46f2a44a-b8b5-4d16-83f2-695a38f46855
      Unique Name:                d69a6e6d-466c-42d2-a20b-8dd63dd12c68
      Friendly Name:              production-orgname
      Org URL:                    https://orgnnnnnnnn.crmnn.dynamics.com
      User Email:                 This email address is being protected from spambots. You need JavaScript enabled to view it.
      User ID:                    5fa5680a-27d0-11ee-970f-2eb5a363657c
      Environment ID:             6529b3bc-27d0-11ee-a201-2eb5a363657c
    
  • list — Lists all of the Dataverse organizations the user has access to

    You'll see output something like this (fake numbers) ad thats very useful for scripting, you can get the Display Name, Environment ID, Environment URL, and Unique Name and use them to do useful things in your CI/CD or ALM pipelines.

    % pac org list
    Display Name       Environment ID                       Environment URL                           Unique Name
    dev-username       e335ef1c-27cd-11ee-8518-2eb5a363657c https://orged1nnnnnnnn.crmnn.dynamics.com 77309443-e6b8-4d38-b94c-0e40d454cce5
    production-orgname eb1e440e-27cd-11ee-ac01-2eb5a363657c https://orgnnnnnnnn.crmnn.dynamics.com    4d8992e0-2106-4613-ad83-1bb08129955c
  • fetch — (Preview) Performs FetchXML query against Dataverse
  • list-settings — List environment settings
  • update-settings — Update environment settings
  • select — Select default organization for current authentication profile

 

pac admin – Commands for environment lifecycle features.

Usage: pac admin [list] [create] [backup] [set-backup-retention-period] [delete] [reset] [list-backups] [restore] [copy] [status] [assign-user] [assign-group] [list-app-templates] [create-service-principal]

  • list — List all environments from your tenant.
    % pac admin list
    
    Listing all environments from your tenant...
    Environment          Environment ID                       Environment Url                         Type      Organization ID
    dev-username           9bc02954-2c55-11ee-8e80-325096b39f47 https://orgnnnnn.crm11.dynamics.com/ Developer a03cc3b6-7f2e-4314-ba6e-387d6a69df59
    production-orgname e37e861e-2c55-11ee-8d45-325096b39f47 https://orgnnnnn6.crm11.dynamics.com/ Default   a9b5a878-64de-4c5a-88c8-4ee040829381
  • create Creates a Dataverse instance in your tenant.
  • backup — Takes a manual backup of your environment.
    % pac admin backup --environment 9bc02954-2c55-11ee-8e80-325096b39f47  --label dev-username-20230727 
    
    Backing up your environment with label : dev-angusf-20230727
    
     Environment Id                           Label                       Backup Expiry             Backup Point Date         User Id                  
    
     9bc02954-2c55-11ee-8e80-325096b39f47     dev-username-20230727        8/3/2023 8:19:59 AM       7/27/2023 8:19:59 AM      d225842f-398c-439e-9c8b-f814f4e9511b
  • set-backup-retention-period Takes a manual backup of your environment.
  • delete Deletes the environment from your tenant.
  • reset Reset the environment from your tenant.
  • list-backups — Lists all backups of your environment.
    % pac admin list-backups --environment 9bc02954-2c55-11ee-8e80-325096b39f47
    
    Listing all backups of your environment with Url : https://orgnnnnnn.crm11.dynamics.com/
    
     Index      Id                                                 Label                                    Expiry                                             Point Date          
    
     1          9683bf13-c394-4a98-a6a0-f122d856959c             dev-username-20230727                      8/3/2023 8:19:59 AM                                7/27/2023 8:19:59 AM
    
  • restore Restores an environment to a given backup.
  • copy Copy Source Environment to Destination Environment.
  • status This command lists the status of all the operations in progress.
  • assign-user Assign a user to a target Dataverse environment with specified security role.
  • assign-group Assign group to target Dataverse environment with specified security role.
  • list-app-templates Lists all supported Dataverse templates of model-driven apps in Dynamics 365.
    % pac admin list-app-templates                                         
    Template Name               Template Location Template Display Name Is Disabled
    D365_CDSSampleApp           unitedstates      Sample App            False
    D365_CustomerService        unitedstates      Customer Service      True
    D365_CustomerServicePro     unitedstates      Customer Service Pro  True
    D365_DeveloperEdition       unitedstates      Developer Edition     True
    D365_FieldService           unitedstates      Field Service         True
    D365_Guides                 unitedstates      Guides                True
    D365_PowerFrameworkTemplate unitedstates      Power Framework       True
    D365_ProjectOperations      unitedstates      Project Operations    True
    D365_RemoteAssist           unitedstates      Remote Assist         True
    D365_Sales                  unitedstates      Sales Enterprise      True
    D365_SalesPro               unitedstates      Sales Pro             True
    D365_SmbMarketing           unitedstates      SMB Marketing         True
    
  • create-service-principal — Add Microsoft Azure Active Directory application and associated application user to the Dataverse environment.

pac application – Commands to install AppSource applications that are prerequisites for the solution work in the target environment

% pac application
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Usage: pac application [list] [install]

  • list — List available Dataverse applications from AppSource
    % pac application list
    Friendly Name                                                  Unique Name                                          Application ID
    Account Onboarding                                             AccountOnboardingAnchor                              a5f0c8b9-adb3-4499-b5e8-f8eb0afd106e
    Agent Productivity Tools                                
    ...
    ...
    Wrap for Power Apps                                            msdyn_MobileAppsSolutionAnchor                       72ad61ed-9ce6-4eb9-af04-9fcb2dbdcdc1
    
  • install Installs Dataverse application to given environment.

pac canvas – Commands for working with canvas app source files

% pac canvas
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Usage: pac canvas [pack] [unpack] [create]

  • pack (Preview) Pack sources into an msapp file
  • unpack (Preview) Extract an msapp file into sources
  • create Generate a canvas app from a custom connector

pac package – Commands for working with solution packages.

% pac package
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Usage: pac package [init] [add-external-package] [add-solution] [add-reference]

  • init — Initializes a directory with a new Dataverse package project
  • add-external-package — Adds a package that is external to the Dataverse solution system to a Package Deployer Package project.
  • add-solution — Adds a prebuilt Dataverse solution file to a Package Deployer Package project.
  • add-reference — Adds reference to Dataverse solution project

pac paportal – Commands for working with Portals support for Microsoft Power Platform CLI.

% pac paportal
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Error: You're missing a sub-command.

Usage: pac paportal [list] [download] [upload]

  • list List all Power Pages websites from the current Dataverse environment.
  • download Download Power Pages website content from the current Dataverse environment.
  • upload Upload Power Pages website content to current Dataverse environment.

pac pcf – Commands for working with Power Apps component framework.

% pac pcf
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Error: You're missing a sub-command.

Usage: pac pcf [init] [push] [version]

  • init Initializes a directory with a new Power Apps component framework project
  • push Import the Power Apps component framework project into the current Dataverse organization
  • version Patch version for controls

pac plugin – Command to create a plug-in project.

% pac plugin
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Error: You're missing a sub-command.

Usage: pac plugin [init] [push]

  • init Initializes a directory with a new Dataverse plug-in class library.
  • push Import plug-in into Dataverse.

pac solution – Commands for working with Dataverse solution projects.

% pac solution
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Error: You're missing a sub-command.

Usage: pac solution [init] [add-reference] [list] [delete] [online-version] [version] [import] [export] [clone] [publish] [upgrade] [add-license] [check] [create-settings] [pack] [unpack] [add-solution-component] [sync]

  • init Initializes a directory with a new Dataverse solution project
  • add-reference Adds a reference from the project in the current directory to the project at 'path'
  • list List all Solutions from the current Dataverse organization
  • delete Delete a solution from Dataverse in the current environment.
  • online-version Sets version for solution loaded in Dataverse.
  • version Update build or revision version for the solution.
  • import Import the solution into Dataverse.
  • export Export a solution from Dataverse.
  • clone Create a solution project based on an existing solution in your organization.
  • publish Publishes all customizations
  • upgrade Option to stage the Dataverse solution for upgrade
  • add-license Add license and plan info to the solution.
  • check Upload a Dataverse solution project to run against the Power Apps Checker service.
  • create-settings Create a settings file from solution zip or solution folder.
  • pack Package solution components on local filesystem into solution.zip (SolutionPackager).
  • unpack Extract solution components from solution.zip onto local filesystem (SolutionPackager).
  • add-solution-component Add one or more solution components to the target unmanaged solution in Dataverse.
  • sync Sync the current Dataverse solution project to the current state of the solution in your organization.

pac telemetry – Manages the telemetry settings.

% pac telemetry
Microsoft PowerPlatform CLI
Version: 1.25.3+g1f959a5
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions

Error: You're missing a sub-command.

Usage: pac telemetry [enable] [disable] [status]

  • enable Choose to send usage information to help Microsoft improve this product
  • disable Choose to not send usage information to help Microsoft improve this product
  • status Show the current status of telemetry.

See also:

https://learn.microsoft.com/en-gb/power-platform/developer/cli/introduction?WT.mc_id=power-81315-dlaskewitz#install-power-platform-cli-for-linuxmacos

https://marketplace.visualstudio.com/items?itemName=microsoft-IsvExpTools.powerplatform-vscode

https://dotnet.microsoft.com/en-us/learn/dotnet/hello-world-tutorial/intro

https://learn.microsoft.com/en-gb/dotnet/core/tools/telemetry

https://devblogs.microsoft.com/powerplatform/getting-started-with-the-power-platform-cli/