PACX ⁓ Connect to Dataverse environment
Tags: powerplatform, pacx, dataverse, opensource
Published: 2024-06-04 15:05:44

We [introduced PACX here](https://dev.to/_neronotte/pacx-command-line-utility-belt-for-power-platform-dataverse-e4e), as a toolbelt containing commands to streamline the application development on Dataverse environments.

In order to run a command, **PACX** must be aware of the Dataverse environment where you want to run the command. This can be achieved using commands under [`pacx auth`](https://github.com/neronotte/Greg.Xrm.Command/wiki/pacx-auth) namespace.

---

## Create a new auth profile

The `pacx auth create` command can be used to create a new connection vs a Dataverse environment. It takes as inputs:

- **--name** (-n): a meaningful name for the connection
- **--conn** (-cs): a [valid dataverse connection string](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect) that can be used to connect to the desired dataverse environment.

> Please remember to enclose the connection string in double quotes "...": some terminal handles the semicolon (;) in the connection string as a command delimiter. [This causes an error while trying to connect to dataverse](https://github.com/neronotte/Greg.Xrm.Command/issues/60).

Once executed, the command will try to use the provided connection string to connect to the environment and executes a `WhoAmI` request to ensure that the connection works properly. If succeeded, it creates and saves on the local machine an authentication profile called as specified in the `--name` argument, and sets it as **default** for the next command executions.

You can create as many authentication profiles as you need. `pacx auth list` command can be used to list all of them, while `pacx auth select` allows to select which auth profile must be use in the subsequent commands.

## List all auth profiles

The `pacx auth list` command can be used to list all the authentication profiles stored in the local machine. It does not require any argument, and will provide the following output

![pacx auth list sample output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6atzyig39z1hc5bx58ep.png)

The first column contains the name of the auth profile, while the second column contains the connection string.

## Peek the right auth profile

The `pacx auth select` command can be used to select which auth profile must be used from now on (until another pacx auth select changes your decision).

It accepts a single argument **--name** (-n) containing the name of the auth profile you want to set as default.

![pacx auth select sample output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zreva7xxxkzsgp2c78ti.png)

## Other useful info

This namespace provides a few other useful commands:
- `pacx auth rename`: can be used to rename an auth profile. It accepts 2 arguments:
  - **--old** (-o): the old name of the auth profile to rename
  - **--new** (-n): the new name of the auth profile
- `pacx auth delete`: deletes a specific auth profile. It accepts a single argument:
  - **--name** (-n): the name of the auth profile to delete
- `pacx auth ping`: tests the connection vs the current default auth profile. No argument required 

You can simply type `pacx auth` in the console to get the list of available commands. Moreover, you can just type the name of a command followed by `--help` if you need help on that specific command arguments.


## References
- [`pacx` official wiki](https://github.com/neronotte/Greg.Xrm.Command/wiki)
- [`pacx auth create` official wiki](https://github.com/neronotte/Greg.Xrm.Command/wiki/pacx-auth-create)
- [`pacx auth list` official wiki](https://github.com/neronotte/Greg.Xrm.Command/wiki/pacx-auth-list)
- [`pacx auth select` official wiki](https://github.com/neronotte/Greg.Xrm.Command/wiki/pacx-auth-select)