Exporting Power Platform Environment Settings using PowerShell

Loading

Exporting Power Platform environment settings allows administrators to back up configuration details, analyze settings, and maintain governance across environments. Using PowerShell, you can extract key environment details, including security settings, Dataverse configurations, and permissions.


Step 1: Install Required PowerShell Modules

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 Power Platform using an Admin account:

Add-PowerAppsAccount

A Microsoft sign-in window will appear. Log in using your Global Admin or Power Platform Admin credentials.

For automation without manual sign-in, use 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 Environment Settings

List all available environments to find the EnvironmentName:

Get-AdminPowerAppEnvironment | Select-Object DisplayName, EnvironmentName, Location, EnvironmentSku

Select the EnvironmentName of the environment you want to export.


Step 4: Export Environment Settings

1. Export General Environment Details

$environmentId = "your-environment-id"

$environmentDetails = Get-AdminPowerAppEnvironment -EnvironmentName $environmentId
$environmentDetails | Format-List

This retrieves key details such as DisplayName, EnvironmentSku, Location, and CreatedBy.


2. Export Dataverse (Common Data Service) Settings

To check if Dataverse is enabled and retrieve database settings:

Get-AdminPowerAppDatabase -EnvironmentName $environmentId | Format-List

This returns Database Capacity, Language, Currency, and State.


3. Export Security Settings (User Permissions and Roles)

Retrieve a list of users and their roles:

Get-AdminPowerAppEnvironmentRoleAssignment -EnvironmentName $environmentId | Select-Object PrincipalEmail, RoleName

4. Export Environment Settings to a CSV File

To save the retrieved details in a CSV file for future reference:

$exportPath = "C:\PowerPlatform\EnvironmentSettings.csv"

$environmentDetails | Select-Object DisplayName, EnvironmentName, Location, EnvironmentSku, CreatedBy |
Export-Csv -Path $exportPath -NoTypeInformation

To export user roles and permissions:

Get-AdminPowerAppEnvironmentRoleAssignment -EnvironmentName $environmentId |
Select-Object PrincipalEmail, RoleName |
Export-Csv -Path "C:\PowerPlatform\UserRoles.csv" -NoTypeInformation

Step 5: Verify Exported Files

Navigate to C:\PowerPlatform and open the CSV files in Excel to verify that the details have been exported correctly.


Step 6: Disconnect from Power Platform

Once done, disconnect the session:

Disconnect-PowerAppsAccount

Leave a Reply

Your email address will not be published. Required fields are marked *