Microsoft Power Platform enables businesses to automate processes, build apps, and analyze data efficiently. Managing Power Platform environments using PowerShell provides administrators with greater control, allowing for automation, bulk operations, and security management.
This guide will cover step-by-step instructions on how to manage Power Platform environments using PowerShell.
Step 1: Prerequisites
1.1 Install PowerShell
Ensure your system has the latest version of PowerShell:
- Windows: PowerShell 5.1 or later
- Mac/Linux: PowerShell Core (7.x recommended)
Check your version by running:
$PSVersionTable.PSVersion
1.2 Permissions Required
To manage Power Platform environments, you must have one of the following roles:
- Global Administrator
- Power Platform Administrator
- Environment Administrator
1.3 Install Required PowerShell Modules
Power Platform requires two main PowerShell modules:
Microsoft.PowerApps.Administration.PowerShell
(for administration tasks)Microsoft.PowerApps.PowerShell
(for managing apps and flows)
Step 2: Installing PowerShell Modules
2.1 Open PowerShell as Administrator
To install the necessary modules, run PowerShell as an Administrator.
2.2 Install the PowerApps Administration Module
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -AllowClobber
2.3 Install the PowerApps Management Module
Install-Module -Name Microsoft.PowerApps.PowerShell -Force -AllowClobber
2.4 Verify Installation
Get-Module -ListAvailable Microsoft.PowerApps*
Step 3: Connecting to Power Platform
3.1 Authenticate Using Interactive Login
Use the following command to log in:
Add-PowerAppsAccount
A Microsoft login prompt will appear. Enter your credentials to authenticate.
3.2 Authenticate Using Service Principal (App Registration)
For automation without user intervention, use an Azure AD App Registration:
- Go to Azure Portal → Azure Active Directory → App Registrations
- Register a new application
- Assign API Permissions for “PowerApps Management” and “PowerApps Administration”
- Generate a Client Secret under “Certificates & Secrets”
Then, connect using PowerShell:
$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 4: Managing Power Platform Environments
4.1 Retrieve All Environments
Get-AdminPowerAppEnvironment
4.2 Retrieve a Specific Environment
Get-AdminPowerAppEnvironment -EnvironmentName "your-environment-id"
4.3 Create a New Environment
New-AdminPowerAppEnvironment -DisplayName "NewEnvironment" -Location "United States" -EnvironmentSku "Production"
4.4 Update Environment Settings
Modify an existing environment’s properties:
Set-AdminPowerAppEnvironment -EnvironmentName "your-environment-id" -DisplayName "UpdatedName"
4.5 Delete an Environment
Remove-AdminPowerAppEnvironment -EnvironmentName "your-environment-id"
Step 5: Managing Power Apps and Flows
5.1 Retrieve All Power Apps
Get-AdminPowerApp
5.2 Retrieve App Details
Get-AdminPowerApp -AppName "your-app-id"
5.3 Retrieve All Power Automate Flows
Get-AdminFlow
5.4 Disable a Flow
Disable-AdminFlow -EnvironmentName "your-environment-id" -FlowName "your-flow-id"
5.5 Enable a Flow
Enable-AdminFlow -EnvironmentName "your-environment-id" -FlowName "your-flow-id"
5.6 Delete a Flow
Remove-AdminFlow -EnvironmentName "your-environment-id" -FlowName "your-flow-id"
Step 6: Managing Users and Permissions
6.1 Retrieve Users in an Environment
Get-AdminPowerAppEnvironmentUser -EnvironmentName "your-environment-id"
6.2 Assign a User to an Environment
Set-AdminPowerAppEnvironmentRoleAssignment -EnvironmentName "your-environment-id" -PrincipalObjectId "user-id" -RoleName "Environment Maker"
6.3 Remove a User from an Environment
Remove-AdminPowerAppEnvironmentRoleAssignment -EnvironmentName "your-environment-id" -PrincipalObjectId "user-id"
Step 7: Managing Connectors and DLP Policies
7.1 Retrieve Connectors in an Environment
Get-AdminPowerAppConnector -EnvironmentName "your-environment-id"
7.2 Retrieve Data Loss Prevention (DLP) Policies
Get-AdminDlpPolicy
7.3 Create a New DLP Policy
New-AdminDlpPolicy -DisplayName "RestrictedPolicy"
7.4 Assign a Connector to a DLP Policy
Set-AdminDlpPolicy -PolicyName "RestrictedPolicy" -ConnectorName "shared-twitter"
7.5 Remove a Connector from a DLP Policy
Remove-AdminDlpPolicyConnector -PolicyName "RestrictedPolicy" -ConnectorName "shared-twitter"
Step 8: Exporting and Importing Power Apps
8.1 Export a Power App
Export-AdminPowerApp -AppName "your-app-id" -PackagePath "C:\Exports\PowerApp.zip"
8.2 Import a Power App
Import-AdminPowerApp -PackagePath "C:\Exports\PowerApp.zip"
Step 9: Disconnecting from Power Platform
After performing all tasks, disconnect to ensure security:
Disconnect-PowerAppsAccount