Managing Power Apps Owners using PowerShell

Loading

Managing Power Apps owners using PowerShell allows administrators to add, remove, and review app owners in Power Platform. This ensures proper access control, governance, and security for organizational apps.


Step 1: Install Required PowerShell Modules

Ensure that 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

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 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: Retrieve Power Apps in an Environment

List all Power Apps in a specific environment:

$environmentId = "your-environment-id"

Get-AdminPowerApp -EnvironmentName $environmentId | Select-Object DisplayName, AppName, CreatedTime, LastModifiedTime

Identify the AppName of the app you want to manage.


Step 4: View Current App Owners

To check who currently owns an app:

$appId = "your-app-id"

Get-AdminPowerAppOwner -AppName $appId

This lists all owners associated with the selected Power App.


Step 5: Add a New Owner to a Power App

To grant ownership access to a new user:

$appId = "your-app-id"
$newOwner = "user@domain.com"

Set-AdminPowerAppOwner -AppName $appId -PrincipalType User -PrincipalObjectId $newOwner

This assigns ownership to the specified user.


Step 6: Remove an Owner from a Power App

To remove an existing owner from an app:

$appId = "your-app-id"
$ownerToRemove = "user@domain.com"

Remove-AdminPowerAppOwner -AppName $appId -PrincipalObjectId $ownerToRemove

Note: You cannot remove the last remaining owner of an app.


Step 7: Export Power Apps Ownership Information (Optional)

For documentation and auditing purposes, export all Power Apps owners to a CSV file:

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

Get-AdminPowerApp -EnvironmentName $environmentId | ForEach-Object {
$appId = $_.AppName
Get-AdminPowerAppOwner -AppName $appId | Select-Object @{Name="AppName";Expression={$_.AppName}}, PrincipalObjectId, PrincipalType
} | Export-Csv -Path $exportPath -NoTypeInformation

This will save all Power Apps and their owners in C:\PowerPlatform\PowerAppsOwners.csv.


Step 8: 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 *