Deleting an unused Power App using PowerShell helps free up resources, manage app lifecycles, and maintain a clean Power Platform environment. This method ensures proper governance and prevents clutter in your Microsoft Power Platform.
Step 1: Install the Required PowerShell Modules
Ensure that 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 installation.
Step 2: Authenticate to Power Platform
Log in using an Admin account:
Add-PowerAppsAccount
For service principal authentication:
$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 All Power Apps
List all Power Apps in a specific environment to find unused apps:
$environmentId = "your-environment-id"
Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, CreatedTime, LastModifiedTime
Check the LastModifiedTime and CreatedTime columns to identify unused or inactive apps.
Step 4: Delete the Unused Power App
Once you have identified the unused app, delete it using:
$appId = "your-app-id"
$environmentId = "your-environment-id"
Remove-AdminPowerApp -AppName $appId -EnvironmentName $environmentId -Confirm:$false
To delete multiple apps in bulk, use:
$appsToDelete = @("app-id-1", "app-id-2", "app-id-3")
foreach ($app in $appsToDelete) {
Remove-AdminPowerApp -AppName $app -EnvironmentName $environmentId -Confirm:$false
}
This command removes the selected Power App without prompting for confirmation.
Step 5: Verify Deletion
List all apps again to confirm that the app has been removed:
Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName
If the app does not appear in the list, it has been successfully deleted.
Step 6: Disconnect from Power Platform
Once done, disconnect the session:
Disconnect-PowerAppsAccount