Deleting a Power Platform environment removes all associated apps, flows, and Dataverse data permanently. This action is irreversible, so it’s crucial to verify before proceeding.
Step 1: Install Required PowerShell Modules
Ensure you have the necessary PowerShell modules installed:
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -AllowClobber
Install-Module -Name Microsoft.PowerApps.PowerShell -Force -AllowClobber
If prompted, press Y to confirm the installation.
Step 2: Authenticate to Power Platform
Connect to Power Platform with your Admin account:
Add-PowerAppsAccount
A Microsoft sign-in window will appear. Log in with your Global Admin or Power Platform Admin credentials.
For service principal authentication (without user interaction), use:
$clientId = "your-client-id"
$clientSecret = "your-client-secret"
$tenantId = "your-tenant-id"
$SecureSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($clientId, $SecureSecret)
Connect-AdminPowerAppEnvironment -TenantId $tenantId -Credential $Credential
Step 3: Retrieve Available Environments
List all Power Platform environments:
Get-AdminPowerAppEnvironment | Select-Object DisplayName, EnvironmentName, Location, EnvironmentSku
Identify the EnvironmentName of the environment you want to delete.
Step 4: Delete a Power Platform Environment
Run the following command to delete an environment:
Remove-AdminPowerAppEnvironment -EnvironmentName "your-environment-id"
Replace "your-environment-id"
with the actual EnvironmentName retrieved in Step 3.
If prompted, confirm the deletion by typing Y.
Step 5: Verify Environment Deletion
To confirm that the environment has been deleted, run:
Get-AdminPowerAppEnvironment | Where-Object { $_.EnvironmentName -eq "your-environment-id" }
If the environment no longer appears in the list, the deletion was successful.
Step 6: Disconnect from Power Platform
Once done, disconnect from Power Platform:
Disconnect-PowerAppsAccount