Listing All Power Platform Environments using PowerShell

Loading

To list all Power Platform environments using PowerShell, follow these steps:


Step 1: Install PowerShell Modules

Ensure you have the required modules installed. If not, install them using the following commands:

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -AllowClobber
Install-Module -Name Microsoft.PowerApps.PowerShell -Force -AllowClobber

If prompted, confirm the installation by pressing Y.


Step 2: Connect to Power Platform

Before retrieving environments, you need to authenticate:

Add-PowerAppsAccount

A Microsoft sign-in window will appear. Use your Administrator or Power Platform Admin credentials.

For service principal authentication (without interactive 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: List All Power Platform Environments

Run the following command to retrieve all environments:

Get-AdminPowerAppEnvironment

This will return a list of all environments along with details such as:

  • Environment Name
  • Display Name
  • Location
  • Environment Type (Production, Sandbox, Trial)
  • Created By
  • Dataverse Status

Step 4: Filter and Display Specific Information

4.1 List Environments with Specific Columns

To show only relevant details:

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

4.2 List Environments in a Specific Region

Get-AdminPowerAppEnvironment | Where-Object { $_.Location -eq "United States" }

4.3 Export Environment List to CSV

Get-AdminPowerAppEnvironment | Select-Object DisplayName, EnvironmentName, Location, EnvironmentSku | Export-Csv -Path "C:\PowerPlatformEnvironments.csv" -NoTypeInformation

Step 5: Retrieve a Specific Environment

If you know the EnvironmentName, you can fetch its details:

Get-AdminPowerAppEnvironment -EnvironmentName "your-environment-id"

Step 6: Disconnect from Power Platform

After retrieving the required data, disconnect to ensure security:

Disconnect-PowerAppsAccount

Leave a Reply

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