Photo by @aloragriffiths / Unsplash.com

First look at Power Platform CLI: Command-line tools for developers

Thanks for reading my blog! If you have any questions or need a second opinion with anything Microsoft Azure or Power Platform related, don't hesitate to contact me. I'm happy to provide my professional services through my company, North Advisors.

During Microsoft Build 2021, there was an announcement on more dev-focused tools for Power Platform. The first bits of Power Platform CLI have now landed, so I wanted to take a look what they capable of.

Installing Power Platform CLI

Installation is easy, but perhaps slightly old-fashioned. Download the setup package (a regular MSI) at https://aka.ms/PowerAppsCLI. The installation hung up on me, so I restarted it once to complete the Nuget package deployments.

Updating the CLI (just in case)

Before actually doing anything, let’s update the package. Yes, you downloaded the latest bits, but it never hurts to update them. You can use Visual Studio’s Developer Command Prompt or a regular command prompt, as both recognize the install directory of the tool in %PATH%. The tool is installed in %USERPROFILE%\AppData\Local\Microsoft\PowerAppsCLI.

To update the CLI, run pac install latest:

It only took 5 seconds to complete.

Authenticating to Power Platform

Now that we definitely have the latest bits, let’s try the tool. The magic command is pac for everything. Try running just pac:

It isn’t too obvious what you should do first. The tool allows you to work with Power Platform admin account, authenticate to the numerous services in Power Platform, work with the Dataverse settings, and work with the different package and solution models of Power Platform.

First, we need to authenticate to the Power Platform. You can either authenticate directly to a specific environment, or you can authenticate as an admin. Let’s use the latter to make this easier for us. Run the following command: pac auth create --kind ADMIN

By default, a browser instance will pop up to let you authenticate to your tenant. It will also prompt for consent for the following permissions:

To verify we’re actually connected (beyond the tool just stating so above), let’s try to run pac org who:

Seems to be working! So, what can we do with the tool now that we’ve connected successfully?

Admin commands

With pac admin you can do basic administrative tasks, such as listing the environments, creating new Dataverse environments, and performing deletes, backups, and restores.

To list all environments, use pac admin list:

Let’s perform a backup of my sandbox environment. Use pac admin backup --url https://<ORG-ID>.crm4.dynamics.com:

To verify the backup exists, use pac admin list-backups --url https://<ORG-ID>.crm4.dynamics.com:

Working with solutions

With pac solution you can work with Power Platform solutions. Think of them as packages you deploy between environments, such as from development to testing. A solution can be either managed or unmanaged – typically indicating that a managed solution is deployed to production and shouldn’t be modified. See further details on this here.

To list all solutions, use pac solution list:

To export a solution (with the intention to move it to a different environment or organization), use pac solution export --path c:\temp\solution.zip --name SolutionName:

This results with a .ZIP file, that looks like this:

And this solution can now be imported with pac solution import.

Closing thoughts

It’s obvious the tool is very much a 1.0, but it seems to be very solid at the same time. It’s intended for admins and developers to initiate new solutions and packages, but also to manage the environments within Power Platform. I would foresee it being most useful in deployment scripts, where a new development environment needs to be provisioned with pre-defined packages, for example.