Managing Power Platform: Delete Unwanted Environments with PAC CLI
Image Source:
Power DevOps
Sep 29, 2023 6:14 PM

Managing Power Platform: Delete Unwanted Environments with PAC CLI

by HubSite 365 about Timo Pertilä (Forward Forever) [MVP]

Power Platform Consultant, Microsoft Business Applications MVP

External Blog Post
Citizen Developer

Power DevOpsPower SelectionM365 Hot News

Master Microsofts Power Platform and automate trial environment deletion with PAC CLI. A detailed approach to ensure effective Power Platform Governance.

Towards Efficient Power DevOps: Unwanted Environment Deletion using PAC CLI

The blog post by Timo Pertilä focuses on the efficient deletion of superfluous environments using PAC CLI (Power Apps Component CLI) within the Power DevOps tool. Pertilä provides his insights based on a training session he spearheaded in which 25 trials were conducted. Although these trials times-out in 30 days, he pondered on whether this process of deletion could be automated.

Pertilä chose to learn and share this process through the PAC CLI rather than Power Automate as he believes it is a faster route to clean 25 environments. As a result, he outlines an approach called 'DETERMINING WHAT TO DELETE', elaborates on it, and provides a constructive script as a solution.

In his 'DETERMINING WHAT TO DELETE' approach, Pertilä suggests that we don't seem to have a feasible method to loop through all environments based on their type in PAC CLI. Thus, he propounds looking at their names as a logical solution for this situation. He notes that there's no specific naming convention for these environments, except how they are labelled by the platform during creation. Thus, deletion based on specific strings within name may work effectively.

In the PAC CLI scripting section, Pertilä breaks down how each command within the scripting assists the process of automated deletion.Click Here For More Info

Furthermore, Pertilä illustrates two examples on how to implement this script. With screenshots from his Visual Studio Code (VS Code), he provides step-by-step snapshots from the code editor to the running results of the Power Apps admin center (PPAC).

For asynchronous processing, he suggests the use of "-a" operator since deletion of environments could be a slow process. To inform his readers about the ongoing asynchronous operations, they can use the 'pac admin status' command.

Extended Scope of Power DevOps

Power DevOps is a crucial part of the Microsoft ecosystem now. It has far-reaching influences on not only managing environment trials but also in administering full-fledged infrastructure. The ability to delete unwanted environments using PAC CLI exhibited by Pertilä signifies the agility of Power DevOps to cater to varied IT demands.

Beyond this feature, Power DevOps encompasses several other powerful features such as continuous integration and continuous delivery (CI/CD), Infrastructure as Code (IaC), testing, and more, which can help in streamlining the development process in an IT setup.

In essence, Power DevOps ensures that a software development organization can reduce its lead time, with an enhanced focus towards accelerated delivery. As a result, operational efficiency and productivity is uplifted, and businesses can experience high-grade outcomes and substantial advancements.

Read the full article Power Platform Governance: Deleting unwanted environments with PAC CLI

Power DevOps - Managing Power Platform: Delete Unwanted Environments with PAC CLI

Learn about Power Platform Governance: Deleting unwanted environments with PAC CLI

Microsoft Power DevOps arena has today evolved bearing the cut-throat pace of technology. The Power Apps CLI (Command Line Interface) is now a hot favorite among tech geeks in its ability to handle Power Platform governance tasks. A particularly interesting use case is the "bulk deletion" of unwanted trial environments. A hands-on exploration of this on-point practicality provides a rich learning opportunity. Think seamless automation replacing manual operations!


An essential aspect in this process is identifying the correct environments for deletion. The type-based sorting may seem tough and prompts a shift towards relying on names instead. As per observation, environment names exhibit no particular conventions and largely seem platform generated. Now, given such a scenario, the ability to automate deletions via PAC CLI becomes engaging to explore. Take for instance, the scenario where the trial environments are named by the platform on creation, such as "Field Service Trial".


Now, let's talk about the actual PAC CLI command lines. Daniel Laskewitz developed this script with help from the Product Group. The standout feature of the 'pac admin list' command is an undocumented - json parameter returning JSON to PowerShell. Here's a quicker look:

  • Declare a variable equal to the given string, denoting environment name.
  • List environments via the pac admin list command and convert the output into a PowerShell object.
  • Initiate a 'foreach' loop within the previously declared variable and run the output including the EnvironmentID property.
  • Finally, to prevent accidental deletions during testing, each environment gets deleted based on the -env parameter's value in the iteration of the 'foreach' loop.


To help understand, let's talk about two real-life examples:

  • Deletion of a 'Field Service Trial'
  • Using the -a operator for asynchronous processing

After testing, we get a clear status of the asyc operations

In essence, with the right PAC CLI script, the command-line interface becomes a powerful tool enabling easy environment deletions. As the saying goes, 'with great power comes great responsibility,' ensure you're looping through the correct environments based on their names! Learn to harness the Power App and drive your DevOps knowledge to an unsurmountable new level!

More links on about Power Platform Governance: Deleting unwanted environments with PAC CLI

Deleting unwanted environments with PAC CLI
Apr 21, 2023 — The command pac admin delete with the –env parameter will delete the environment in the iteration of the foreach loop, based on variable and ...
Delete an environment in Power Platform admin center
Feb 14, 2022 — Select an environment and then select Delete. Provide the confirmation data and then select Confirm.
Microsoft Power Platform CLI support for Power Pages
Sep 27, 2023 — In order to delete the site content records in one environment and also delete the same content records in another environment using the PAC ...


Power Platform Governance, PAC CLI, Deleting environments, PAC CLI unwanted environments, Power Platform PAC CLI, Power Platform Environment Management, PAC CLI Governance, Delete Environments PAC CLI, Power Platform Delete Environments, PAC CLI Power Platform