PowerShell provides a powerful way to create and manage Power Apps programmatically. By using PowerShell, administrators can automate app creation, configure environments, and manage permissions efficiently.
Step 1: Install Required PowerShell Modules
Before you create a Power App, 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
You need to authenticate your PowerShell session with your Power Platform environment.
Add-PowerAppsAccount
A Microsoft sign-in window will appear. Log in using your Global Admin or Power Platform Admin credentials.
For service principal authentication (without manual login), 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: Select the Environment for Your Power App
List all available Power Platform environments:
Get-AdminPowerAppEnvironment | Select-Object DisplayName, EnvironmentName, Location, EnvironmentSku
Choose the EnvironmentName where you want to create your Power App.
Step 4: Create a New Power App
Use the following command to create a new canvas app:
$environmentId = "your-environment-id"
$appName = "NewPowerApp"
$appDisplayName = "My First Power App"
$appDescription = "This is a demo Power App created using PowerShell"
New-AdminPowerApp -EnvironmentName $environmentId -AppName $appName -DisplayName $appDisplayName -Description $appDescription
This command will create a blank Power App inside the specified environment.
Step 5: Verify the Created Power App
Once the app is created, you can verify it by listing all apps in the environment:
Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, CreatedTime, LastModifiedTime
This will display all Power Apps in the selected environment, including the new app.
Step 6: Assign an Owner to the Power App (Optional)
If you need to assign an owner to the newly created app:
$appId = "your-app-id"
$newOwner = "user@domain.com"
Set-AdminPowerAppOwner -AppName $appId -PrincipalType User -PrincipalObjectId $newOwner
Step 7: Export Power App Information to a CSV (Optional)
For documentation and auditing purposes, export all Power Apps details to a CSV file:
$exportPath = "C:\PowerPlatform\PowerAppsList.csv"
Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, CreatedTime, LastModifiedTime |
Export-Csv -Path $exportPath -NoTypeInformation
This will save the app details to C:\PowerPlatform\PowerAppsList.csv.
Step 8: Disconnect from Power Platform
Once done, disconnect the session:
Disconnect-PowerAppsAccount