Download and Upload Power Page Sites with Power Platform CLI Tool (pac)

Download and Upload Power Page Sites with Power Platform CLI Tool (pac)

If you're serious about getting started with developing on the Microsoft Power Platform, specifically Power Pages, then you should be using Visual Studio. You can dip your toe in easily, and launch Visual Studio Code in the browser from the Power Pages Admin Center, by clicking on the Edit code button at the top right of any of the pages in the Design Studio.

Sign your life away to the dark-theme overloads.

And then you get a folder structure representation of your Power Pages site.

Simply edit a page and hit save, (then sync the site) and it's live on the interwebs! Much more control for the ProCoder than the editor you get in Power Pages Design Studio.

But what if you want to use Node.js for things like SCSS, TypeScript, or any other build time pre-processor where you need a local copy of the site's assets.

Power Platform CLI Tool

The reason it's known as 'pac' is as old as Microsoft have been renaming products. The Power Apps CLI tool evolved to cover more of the Power Platform.

Installing Power Platform CLI Tool (pac)

Various ways to install it, and it supports Windows, Linux, or macOS

  • Windows, Linux, or macOS
    • Visual Studio Code extension (only works with the application, and not with the web version)
    • Use .NET Tool
  • Windows only
    • Or there is the a Windows MSI installer

Available from Microsoft for Windows, Linux, and macOS.

To check it's installed correctly, just type pac from a command prompt or terminal session inside Visual Studio Code (if you've deployed the extension).

Installed and ready to go

Authentication

To sign in to a specific environment, type in:

pac auth create --name <name_for_creds> --environment <url|id|unique_name|partial_name>

That will then pop up the Microsoft Entra ID authentication flow for you to sign in.

To see what cached credentials exist, use the following command:

And then select the credentials you want to be default:

pac auth select < --index | --name >
This was already default for me, but it's only for illustrative purposes, calm down.

Find and Download Power Pages Sites

Finding the unique Website Id for the site is as easy as typing pac pages list once you have successfully authenticated.

Just use the Website Id that matches the friendly name of the site you're after.

pac pages download --webSiteId <guid> --path <local_folder> --modelVersion 2

If you used the --environment parameter when you ran the pac create auth step above, then you don't need to specify it here, but if you use the same credentials with multiple environments, then you can specify --environment on this command instead.

--modelVersion refers to the type of Power Page site, either the Standard (--modelVersion 1) or Enhanced Data Model (--modelVersion 2). All newly created sites will be the Enhanced Data Model, if you're unsure you can find out via the Power Platform Admin Center, go to the environment it's in, then Resources, then Power Page Sites, then select the site from the list, and in the Site Details section it will have a heading 'Data Model' with either Standard or Enhanced underneath.

Within the path, it will create a sub-folder for the site, with a similar structure to what you saw at the start inside Visual Studio Code for the Web.

But you'll also see a load of YAML files. These contain metadata about the corresponding asset (such as it's record-id or display name), or some metadata about the site permissions, settings, or other configuration.

Upload

Once you've worked your magic, simply type in the following:

pac pages upload --path <local_folder> --modelVersion 2

And it will check the files and upload anything that has changed.

Give the site a 'sync' to clear the cache and you should be good to go!

What's Next?

That's all well and good, but it's manual, and it's not very friendly if you have multiple people working on the same site.

Next up, I'll write up the process of setting up GitHub for the Power Pages Site and using GitHub Actions to upload changes as they're committed.

Stay tuned!