The Power Platform Command Line Interface (CLI) is a powerful tool that enables developers and administrators to interact with Power Platform resources, including Power Apps portals, programmatically from the command line. This guide focuses on how to use Power Platform CLI for Power Apps portal management, covering installation, authentication, and key portal operations.
1. Introduction to Power Platform CLI
Power Platform CLI is a developer tool that allows you to manage environments, solutions, components, and specifically portals within the Microsoft Power Platform. It simplifies automation, integration with CI/CD pipelines, and advanced customization beyond what the portal studio offers.
Portals in Power Platform are used to build low-code external-facing websites that integrate with Dataverse.
2. Prerequisites
Before using the CLI, ensure the following are in place:
- Access to a Power Platform environment with a Power Apps portal provisioned.
- Admin or Maker permissions on the environment.
- Node.js installed on your machine.
- Git and .NET Core SDK (optional but useful for some dev tasks).
3. Installation of Power Platform CLI
Power Platform CLI can be installed via the Microsoft.PowerPlatform.Cli
NuGet package or as part of the Power Platform Tools extension in Visual Studio Code.
To install via .NET CLI:
dotnet tool install --global Microsoft.PowerPlatform.Cli
To update later:
dotnet tool update --global Microsoft.PowerPlatform.Cli
After installation, confirm it by running:
pac --version
4. Authenticating with Power Platform
Before managing portals, you need to authenticate.
Login command:
pac auth create --url https://yourorg.crm.dynamics.com
Options:
--url
is your Dataverse environment URL.- Use
--kind ADMIN
if working with admin operations.
To list all authenticated profiles:
pac auth list
To set an active profile:
pac auth select --index 0
This allows switching between different environments easily.
5. Listing Portals
To view all portals in the current environment:
pac portal list
This command returns a list of portals, including their ID, Name, Website ID, and Environment URL.
6. Downloading a Portal (Portal Source Code)
This is one of the most powerful features: extracting a portal into source code format to enable version control and development.
pac portal download --path "C:\Portals\MyPortal" --name "PortalName"
Options:
--path
: Specifies where to store downloaded portal content.--name
: The portal’s name in your environment.
The folder structure includes:
webpages/
,webfiles/
,templates/
,content-snippets/
, andsite-settings/
.
These are YAML or JSON representations of the portal components.
7. Making Local Changes
After downloading the portal, you can edit portal components directly using a code editor (e.g., VS Code).
Typical changes:
- Modify
webpages
to update content. - Update
site-settings
for configurations. - Adjust
webfiles
for static assets (CSS, JS, Images).
Version control these changes using Git for collaboration and CI/CD deployment.
8. Uploading a Portal (Push Changes)
Once changes are done, you can upload them back to the portal:
pac portal upload --path "C:\Portals\MyPortal"
This will push your local modifications into the Power Apps portal and overwrite existing content where applicable.
You can validate your changes through the live portal or in staging.
9. Portal Operations
Reset Portal:
Resets the portal to remove local configurations or errors.
pac portal reset --path "C:\Portals\MyPortal"
Clone Portal:
To clone an existing portal configuration:
pac portal clone --path "C:\NewPortalFolder" --name "OriginalPortalName"
Deploy Portal to Target Environment:
First, use the upload
command in the source environment. Then, extract solution and portal metadata, and import it to the target using:
pac solution export --path "C:\Solutions" --name "PortalSolution"
pac solution import --path "C:\Solutions" --name "PortalSolution.zip"
Portals must be reconfigured with environment-specific site settings (URLs, keys, etc.).
10. Portal Pack & Unpack Operations
To enable easy CI/CD or DevOps pipelines, portals can be packed and unpacked into solution packages.
Unpack portal solution:
pac solution unpack --zipfile "PortalSolution.zip" --folder "UnpackedPortal"
Pack portal solution:
pac solution pack --folder "UnpackedPortal" --zipfile "PortalSolutionPacked.zip"
Use these in Azure DevOps or GitHub Actions for automated deployments.
11. Portal Schema and Configuration Files
Each component (webpage, template, snippet) is represented as a YAML file. You can customize them manually.
Example webpage.yaml
:
name: Home
website: Default Portal
page-template: HomePage
partial-url: home
You can create new files, modify existing ones, or delete unused components locally before uploading.
12. Best Practices for CLI Portal Management
- Always backup your current portal before upload.
- Use version control (Git) to track changes.
- Maintain a consistent folder structure and naming convention.
- Apply CI/CD practices for test, staging, and production portals.
- Use different authentication profiles for dev/test/prod.
- Frequently use
pac portal list
to ensure you’re working with the correct environment and portal.
13. Automating CLI Commands with Scripts
For repeatable tasks, you can automate CLI operations using PowerShell or Bash scripts.
Example PowerShell script:
pac auth select --index 0
pac portal download --path "C:\Portals\MyPortal"
# Make changes...
pac portal upload --path "C:\Portals\MyPortal"
Such scripts are useful for developers managing multiple environments or working in teams.
14. Troubleshooting Common Errors
- “Portal not found”: Double-check portal name and active environment.
- Authentication issues: Ensure correct URL and profile index.
- Upload conflicts: Sync changes carefully, and avoid overwriting production without testing.
- Slow performance: Break down portal into smaller modules or optimize large web files.