I’ve been spending some time with the modern tooling and thought it would help to blog some of the step-by-step to help others.

Install PAC CLI

Open a command prompt and type pac to see if the Power Platforms CLI (command line interface) is installed on your machine. If you get an error (not found) you’ll need to install the PAC CLI.

Go to https://aka.ms/PowerAppsCLI to download the installer. Then run the installer. If the CLI installs successfully than the pac command should run successfully and display a list of commands.

Display of the `pac` command output when the Power Platform CLI application is installed.

Ensure you are working with the latest version by running the command pac install latest and pac use latest.

Example output of issuing a 'pac install latest' and a 'pac use latest' command.

And if you are wondering, yes you can install and use previous versions by specifying the version number. Try using the above commands changing latest to 1.12.2. Just be sure to do a pac use latest to switch back to the latest version.

Why would you select a version other than the latest?

If you are writing a script you may want to ensure specific behavior regardless of what version is installed on the machine. By using these commands you can ensure that your scripts pac references execute using a known and tested version of the cli.

Connecting to a Tenant

Now that you’ve got PAC CLI working you’ll likely want to connect to a tenant and, potentially, select a specific organization to work with using commands.

You’ll use the pac auth command to connect, list, and select a tenant. The PAC CLI tool supports connections to multiple tenants.

To get started we’ll see if there are any existing connections. Issue a pac auth list command to show any existing tenant connections.

Result of running `pac auth list` when no profiles are saved on the system.

If you have a commercial (not a sovereign cloud such as GCC or GCC High) that you can authenticate with using a browser-based (Azure AD) login you can issue the command pac auth create to quickly create an authentication. You’ll get a pop-up browser window allowing you to select an existing connection or create a new connection.

After signing in you’ll be returned to the terminal window and see a successful connection.

Shows the results of running `pac auth create` and successfully connecting to a tenant.

For more complicated authentication scenarios, such as Managed Identities and App Id/Client Secret, you can use the pac auth help command to identify the appropriate switches. For US users in Gov Cloud (GCC, GCC High, DOD) environments you will need to use the --cloud switch to indicate the cloud instance you want to authenticate with.

Shows the result of running `pac auth create held` to get a list of switch options for more advanced authentication requirementes.

You can authenticate to multiple tenants and authenticate to the same tenant with different credentials.

Shows the result of running a `pac auth create` command and successfully connecting to a tenant. Then running the `pac auth list` command to see available profiles.

I’ve authenticated to the same tenant (thinkplusplus.com) as two different users, as shown in the image there are two authentication records (1 and 2) when I run pac auth list.

By looking at the list the asterisk (*) indicates which authentication profile (user in a tenant) is currently active.

I can switch by using the index (number) with the pac auth select --index [INDEX] command. To switch to the first profile I enter pac auth select --index 1.

Results of running a `pac auth select` command and then a `pac auth list` command. The `pac auth list` shows that the selected profile is now the active profile.

Looking at the two previous images you’ll selected profile has changed from 2 to 1. This means any interactions performed by the pac command will occur using the context of the user shown on the selected profile.

Having to refer to authentication profiles by number can become inconvenient and you cannot reliably trust that a specific index will match to a specific profile. The better way to reference profiles is to assign them unique names. We can do this by specifying the name when authenticating using the --name switch or assigning a name after authenticating using the pac auth name --index [INDEX] --name [NAME] .

Result from running `pac auth list` after assigning names to each environment.

Now we can switch between profiles using the --name switch. For example, to switch from the Nick to the Mike profile I run the command pac auth select --name "Mike".

Multiple Organizations

Within in a Power Platform tenant there will be multiple environments. Environments are still commonly referred to as organizations, and the PAC CLI tool is no different. Environments are managed with the org command. You can list out the environments you have access to with the selected profile by issuing the command pac org list.

A list of available environments from running the `pac org list` command. Shows Display Name, Environment ID, Environment URL, and Unique Name.

You can then select an environment by providing its Display Name, Environment Id, Environment URL, or Unique Name value using the command pac org select --environment [VALUE]. For the value it’ll take a partial of the Unique Name or Display Name but not for any of the other values.

Result of issues a `pac org select` command for the 'acc' environment. Shows an environment was found and selected.

WhoAmI the PAC CLI way

The WhoAmIRequest() is a classical first call when programming against the Dataverse API, especially when writing command line applications. It provides an output of exactly who the user was and what environment/organization was being accessed. The PAC CLI tool provides an equivalent command, pac org who.

Display of content from running the `pac org who` command. Renders the current Org ID, Unique Name, Friendly Name, Org URL, User Email, User ID, and Environment ID.

That’s a wrap folks…we’ve covered installing the PAC CLI tool, connecting to a tenant, and selecting an organization. From here you can start using any of the commands and verbs in pac to work with Power Platform.

The full PAC CLI command reference is available at: Microsoft Power Platform CLI Command Groups – Power Platform | Microsoft Learn.