To check environment variables in Power Platform using PowerShell, follow these steps:
Step 1: Install Required PowerShell Modules
Before running Power Platform commands, install and import the required modules.
# Install Power Platform PowerShell module if not installed
Install-Module -Name Microsoft.PowerPlatform.Dataverse.Client -Scope CurrentUser -Force -AllowClobber
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Scope CurrentUser -Force
Install-Module -Name Microsoft.PowerApps.PowerShell -Scope CurrentUser -Force
Step 2: Connect to Power Platform
Authenticate using your credentials or service principal.
# Connect using interactive login
Add-PowerAppsAccount
OR, if using a service principal:
# Connect using a service principal (Requires Application ID, Tenant ID, and Certificate)
$AppId = "YOUR_APP_ID"
$TenantId = "YOUR_TENANT_ID"
$CertificateThumbprint = "YOUR_CERT_THUMBPRINT"
Connect-AdminPowerAppEnvironment -ApplicationId $AppId -TenantId $TenantId -CertificateThumbprint $CertificateThumbprint
Step 3: Retrieve Environment Variables
To list all environment variables in a specific environment, use:
# Get all environments
$environments = Get-AdminPowerAppEnvironment
# Select an environment (modify accordingly)
$envId = ($environments | Where-Object { $_.DisplayName -eq "Your Environment Name" }).EnvironmentName
# Get all environment variables for the selected environment
$envVariables = Get-AdminPowerAppEnvironmentVariable -EnvironmentName $envId
# Display the environment variables
$envVariables | Format-Table DisplayName, DefaultValue, Value, SchemaName
Step 4: Export Environment Variables to a CSV File
To store the environment variables in a file:
$envVariables | Select-Object DisplayName, DefaultValue, Value, SchemaName | Export-Csv -Path "C:\PowerPlatform\EnvVariables.csv" -NoTypeInformation
Step 5: Check a Specific Environment Variable
If you need details about a specific variable, modify this:
$variableName = "YourVariableName"
$specificVariable = $envVariables | Where-Object { $_.DisplayName -eq $variableName }
$specificVariable
Step 6: Disconnect Session (Optional)
After execution, disconnect the session.
Disconnect-AdminPowerAppEnvironment