Creating a new Power Platform environment using PowerShell allows administrators to automate environment management, ensuring the correct configurations are applied efficiently. This is useful for governance, testing, or segregating workloads in different environments.
Step 1: Install Required PowerShell Modules
Before creating a new environment, ensure you have installed the necessary PowerShell modules:
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 the Power Platform using your Admin account:
Add-PowerAppsAccount
This will open a Microsoft sign-in window where you must authenticate 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: Define Environment Parameters
To create a new Power Platform environment, define the required parameters:
- DisplayName – Name of the environment
- Location – Datacenter region (e.g.,
United States
,Europe
,India
) - EnvironmentSku – Type of environment (
Production
,Sandbox
,Trial
) - Dataverse – Enable or disable Dataverse (formerly Common Data Service)
- SecurityGroupId – Optional security group to restrict access
Example variables:
$environmentName = "NewTestEnvironment"
$displayName = "Test Environment"
$location = "United States"
$environmentType = "Sandbox"
$securityGroupId = "your-security-group-id" # Leave empty if not restricting access
Step 4: Create a New Power Platform Environment
Run the following command to create the environment:
New-AdminPowerAppEnvironment -DisplayName $displayName -LocationName $location -EnvironmentSku $environmentType -SecurityGroupId $securityGroupId
To create an environment with Dataverse, add the -CreateDatabase $true
parameter:
New-AdminPowerAppEnvironment -DisplayName $displayName -LocationName $location -EnvironmentSku $environmentType -SecurityGroupId $securityGroupId -CreateDatabase $true
If you want to define a specific currency and language for Dataverse:
New-AdminPowerAppEnvironment -DisplayName $displayName -LocationName $location -EnvironmentSku $environmentType -SecurityGroupId $securityGroupId -CreateDatabase $true -CurrencyName "USD" -LanguageName "EN"
Step 5: Verify the New Environment
To check if the environment was successfully created:
Get-AdminPowerAppEnvironment | Where-Object { $_.DisplayName -eq "Test Environment" }
This should return the details of the newly created environment.
Step 6: Assign Permissions to Users (Optional)
After creating an environment, you may want to assign users System Administrator or Maker roles:
$environmentId = "your-environment-id"
$userEmail = "user@domain.com"
Set-AdminPowerAppEnvironmentRoleAssignment -EnvironmentName $environmentId -PrincipalEmail $userEmail -RoleName "Environment Maker"
To assign System Administrator role:
Set-AdminPowerAppEnvironmentRoleAssignment -EnvironmentName $environmentId -PrincipalEmail $userEmail -RoleName "System Administrator"
Step 7: Disconnect from Power Platform
Once you are done, disconnect from the Power Platform:
Disconnect-PowerAppsAccount