Enabling or disabling a Power App using PowerShell helps administrators control app availability within an organization. This is useful for maintenance, security, or access control.
Step 1: Install Required PowerShell Modules
Before managing Power Apps, 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 your Power Platform environment:
Add-PowerAppsAccount
Log in using an Admin account when prompted.
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 the Power App Details
List all Power Apps in a specific environment:
$environmentId = "your-environment-id"
Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, CreatedTime, LastModifiedTime
Identify the AppName of the app you want to enable or disable.
Step 4: Disable a Power App
To disable a Power App, use the following command:
$environmentId = "your-environment-id"
$appId = "your-app-id"
Set-AdminPowerApp -AppName $appId -EnvironmentName $environmentId -IsEnabled $false
Once disabled, users will no longer be able to access the app.
Step 5: Enable a Power App
To re-enable the Power App, use the following command:
$environmentId = "your-environment-id"
$appId = "your-app-id"
Set-AdminPowerApp -AppName $appId -EnvironmentName $environmentId -IsEnabled $true
This will restore the app’s availability for users.
Step 6: Verify the App Status
Check whether the app is enabled or disabled:
$environmentId = "your-environment-id"
$appId = "your-app-id"
Get-AdminPowerApp -AppName $appId -EnvironmentName $environmentId | Select-Object DisplayName, AppName, IsEnabled
If IsEnabled is True, the app is active; if False, it is disabled.
Step 7: Export App Status to a CSV (Optional)
For tracking and documentation purposes, export the app details to a CSV file:
$exportPath = "C:\PowerPlatform\PowerAppsStatus.csv"
Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, IsEnabled |
Export-Csv -Path $exportPath -NoTypeInformation
This will save the Power Apps status to C:\PowerPlatform\PowerAppsStatus.csv.
Step 8: Disconnect from Power Platform
Once done, disconnect the session:
Disconnect-PowerAppsAccount