Enforcing Power Platform App Naming Conventions using PowerShell

Loading

Naming conventions in Power Platform help maintain consistency, governance, and easier management of apps. By using PowerShell, admins can enforce a naming convention by detecting improperly named apps and renaming them.

What You’ll Learn:

Connecting to Power Platform
Retrieving all Power Apps
Defining and enforcing naming conventions
Renaming apps that don’t follow the convention
Automating the enforcement process


Step 1: Prerequisites

1. Install Required PowerShell Modules

Ensure you have the necessary modules installed:

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

2. Connect to Power Platform

Authenticate using your admin account:

Add-PowerAppsAccount

Now you can manage Power Apps using PowerShell.


Step 2: Retrieve All Power Apps

To get a list of all apps:

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

This displays all apps along with their details.


Step 3: Define the Naming Convention

Let’s say we enforce the format:
APP_<Department><Function><CreatorName>
(Example: APP_HR_LeaveTracker_JSmith)


Step 4: Identify Apps That Don’t Follow the Convention

Run the following script to find misnamed apps:

$regexPattern = "^APP_[A-Z]+_[A-Za-z0-9]+_[A-Za-z0-9]+$"

$apps = Get-AdminPowerApp | Select-Object DisplayName, AppName, EnvironmentName

$nonCompliantApps = $apps | Where-Object { $_.DisplayName -notmatch $regexPattern }

if ($nonCompliantApps) {
Write-Output "Non-compliant Apps Found:"
$nonCompliantApps | ForEach-Object { Write-Output $_.DisplayName }
} else {
Write-Output "All apps follow the naming convention."
}

This script finds apps that don’t match the defined format.


Step 5: Rename Non-Compliant Apps

Since Power Platform does not support direct renaming, the best approach is to notify the owner or create a renamed copy.

Option 1: Notify App Owners

foreach ($app in $nonCompliantApps) {
Write-Output "App '$($app.DisplayName)' in environment '$($app.EnvironmentName)' does not follow the naming convention."
# Send an email or log it in a report
}

This informs owners to rename their apps manually.


Option 2: Create a Copy with the Correct Name

You can duplicate the app under the correct name and delete the old one manually:

foreach ($app in $nonCompliantApps) {
$newName = "APP_Default_" + $app.DisplayName
New-PowerApp -DisplayName $newName -EnvironmentName $app.EnvironmentName
Write-Output "Created a renamed copy: $newName"
}

This ensures that non-compliant apps follow the naming standard.


Step 6: Automate the Process

To schedule this script weekly in Task Scheduler:

  1. Open Task Scheduler
  2. Click Create Basic Task
  3. Set recurrence to weekly
  4. Choose Start a ProgramPowerShell.exe
  5. Add script path: -File "C:\Scripts\Enforce_Naming.ps1"
  6. Click Finish

Now, the script will enforce naming conventions automatically.

Leave a Reply

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