Fixed: "No Active Environment Set for the Current Auth Profile" in Power Platform CLI
The Power Platform CLI signed me in without a problem, and the very next command failed: No active environment set for the current auth profile. The sign-in had created a profile with no environment attached. One command, pac env select, fixed it.
What I Was Doing
Part 12 of the Career Development Plan series uses the Power Platform CLI (pac) to export and check solutions. I installed it and signed in with a device code, without the --environment option (How to Sign In to the Power Platform CLI with pac auth create):
pac auth create --deviceCode
The sign-in finished:
'admin@example.com' authenticated successfully.
Authentication profile created
* UNIVERSAL : admin@example.com Public
What I Expected
Microsoft's introduction to the CLI says that if you leave out --environment, you're connected to the default environment. My tenant has only one environment, its default one, so I expected the next command to use it.
What I Got
I asked the CLI which environment it was connected to, with pac org who, the older name of pac env who:
$ pac org who
Connected as admin@example.com
Microsoft PowerPlatform CLI
Version: 2.14.1+g6f517e5 (.NET 10.0.13)
Online documentation: https://aka.ms/PowerPlatformCLI
Feedback, Suggestions, Issues: https://github.com/microsoft/powerplatform-build-tools/discussions
Error: No active environment set for the current auth profile. Specify an environment via the `--environment` argument or use an auth profile with an active environment. Alternatively, you can use `pac org select` to set the active environment for the current auth profile.
pac env who gave the same error. The list of profiles showed why: the Environment and Environment Url columns were empty.
$ pac auth list
Index Active Kind Name User Cloud Type Environment Environment Url ERP URL
[1] * UNIVERSAL admin@example.com Public User
What I Checked
- The
pac auth createreference. Its--environmentoption sets the default environment of the new profile, as an ID, a URL, a unique name or part of a name (pac auth). I hadn't given one. - The
pac envreference. Since version 1.32,pac orgis calledpac env;orgstill works (pac env).pac env selectselects the default organization for the current authentication profile, andpac env listlists the environments you can choose from. - What the error itself suggests:
--environmenton each command, a profile that has an environment, orpac org select, the old name ofpac env select.
Why It Happens
A profile created without --environment here was a UNIVERSAL profile with no active environment, whatever the introduction's sentence suggests. Commands that work with an environment's data, such as pac env who or pac solution export, need one, so they stop until the profile has an environment or you name one with --environment.
The Fix
1. List the environments
pac env list
Connected as admin@example.com
Active Display Name Environment ID Environment URL Unique Name
Default Environment 00000000-0000-0000-0000-000000000000 https://org00000000.crm.dynamics.com/ unq00000000000000000000000000000000
The Active column is empty: none is selected. Note the display name of the one you want.
2. Select it
pac env select --environment "Default Environment"
Connected as admin@example.com
Looking for environment ''Default Environment''
Validating connection...
Connected to... Default Environment
Selected org 'Default Environment' 'https://org00000000.crm.dynamics.com/' for current authentication profile.
Use your own environment's name, its URL or its ID. The name here is this tenant's default environment.
After the Fix
pac env who now describes the environment:
$ pac env who
Connected as admin@example.com
Connected to... Default Environment
Organization Information
Org ID: 00000000-0000-0000-0000-000000000000
Unique Name: unq00000000000000000000000000000000
Friendly Name: Default Environment
Org URL: https://org00000000.crm.dynamics.com/
User Email: admin@example.com
User ID: 00000000-0000-0000-0000-000000000000
Environment ID: 00000000-0000-0000-0000-000000000000
And the profile has it:
$ pac auth list
Index Active Kind Name User Cloud Type Environment Environment Url ERP URL
[1] * UNIVERSAL admin@example.com Public User Default Environment https://org00000000.crm.dynamics.com/
Every command after that, from pac solution list to pac solution export, worked without --environment.
Do It in One Step Next Time
The pac auth create reference lets you name the environment when you sign in, with --environment and the same kinds of values as pac env select. I fixed my profile afterwards, so that's the route I ran.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Signing in without --environment | The profile has no active environment | Run pac env select once |
Typing a name that isn't in pac env list | The CLI can't find the environment | Copy the display name, URL or ID from pac env list |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No active environment set for the current auth profile | The profile has no environment | pac env select --environment "<name>" |
pac env list shows no environments | The account can't see any Dataverse environment | Sign in with an account that's a member of one |
| A command works on the wrong environment | Another profile or environment is active | Check pac auth list and pac env who |
FAQ
What's the difference between pac org and pac env?
Only the name. Microsoft renamed org to env in version 1.32 and recommends env; org still works, which is why the error message mentions pac org select.
Can I name the environment on a single command instead?
Yes. Commands that work with an environment accept --environment, as the error message says. Selecting it once saves typing it every time.
Conclusion
A profile made without --environment had no active environment, so every environment command stopped with No active environment set for the current auth profile. pac env list shows your environments, and pac env select --environment "<name>" attaches one to the profile for good.
