PowerShell Function: Get-UnusedPowerApps
Get-UnusedPowerApps
Overview
Get-UnusedPowerApps is a PowerShell function that helps Power Platform administrators identify unused Power Apps across their environments. It identifies apps that either have no assigned users or haven't been modified for a specified period (default: 180 days).
This tool is particularly valuable for:
- Environment cleanup initiatives
- License optimization efforts
- Security reviews
- Governance processes
- Application lifecycle management
Prerequisites
- PowerShell 5.1 or higher
- Microsoft.PowerApps.Administration.PowerShell module installed
- Power Platform Administrator permissions
- Active authenticated session (via Add-PowerAppsAccount)
Installation
Option 1: Import as a Module
- Save the script as PowerPlatformTools.psm1
- Import it into your PowerShell session:
Import-Module .\PowerPlatformTools.psm1
Option 2: Dot-Source the Function
. .\Get-UnusedPowerApps.ps1
Syntax
Get-UnusedPowerApps -EnvironmentName <String> [-UnusedDays <Int32>] [-IncludeAppDetails] [-ExportFormat <String>] [-ExportPath <String>]
Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
EnvironmentName | String | Yes | - | The ID of the Power Platform environment to check. Can be piped in from other commands. |
UnusedDays | Int32 | No | 180 | Number of days since last modification to consider an app as "unused". |
IncludeAppDetails | Switch | No | False | Include additional app details in the results, like app type, description, and creation info. |
ExportFormat | String | No | "None" | Format for exporting results. Options are: "None", "CSV", or "JSON". |
ExportPath | String | No | Auto-generated | Path to save the export file. If not specified, a default path with timestamp is used. |
Output
The function returns an array of PowerShell objects with the following properties for each unused app:
Property | Description |
---|---|
AppName | Display name of the app |
AppId | Unique identifier of the app |
EnvironmentName | Name/display name of the environment |
EnvironmentId | ID of the environment |
CreatedTime | When the app was created |
LastModifiedTime | When the app was last modified |
DaysSinceLastModified | Number of days since the app was last modified |
HasUsers | Whether the app has any assigned users |
UserCount | Number of assigned users |
UsedRecently | Whether the app has been modified within the specified unused days threshold |
Owner | Display name of the app owner |
OwnerEmail | Email address of the app owner |
UnusedReason | Reason why the app is considered unused ("No Users Assigned" or "Not Used in Last X Days") |
When IncludeAppDetails is specified, additional properties include:
- AppType
- Description
- CreatedBy
- CreatedByEmail
- IsHeroApp
- IsFeaturedApp
Examples
Example 1: Find unused apps in a specific environment
Get-UnusedPowerApps -EnvironmentName "12345678-1234-1234-1234-1234567890ab"
Returns all unused Power Apps in the specified environment.
Example 2: Find apps unused in the last 90 days
Get-UnusedPowerApps -EnvironmentName "12345678-1234-1234-1234-1234567890ab" -UnusedDays 90
Returns Power Apps that have no users or haven't been modified in the last 90 days.
Example 3: Export results to CSV
Get-UnusedPowerApps -EnvironmentName "12345678-1234-1234-1234-1234567890ab" -ExportFormat CSV
Returns unused Power Apps and exports the results to a CSV file in the current directory.
Example 4: Process all environments and export to JSON
Get-AdminPowerAppEnvironment | Select-Object -ExpandProperty EnvironmentName | Get-UnusedPowerApps -ExportFormat JSON -ExportPath "C:\Reports\UnusedApps.json"
Processes all environments and exports the combined results to a JSON file.
Example 5: Find apps in all Sandbox environments
Get-AdminPowerAppEnvironment | Where-Object { $_.EnvironmentType -eq "Sandbox" } | Select-Object -ExpandProperty EnvironmentName | Get-UnusedPowerApps -IncludeAppDetails
Finds unused apps in all sandbox environments with detailed information.
Practical Applications
Regular Cleanup
Set up a monthly automated job to identify unused applications:
# Connect using service principal (recommended for automation) Add-PowerAppsAccount -TenantID $tenantId -ApplicationId $applicationId -ClientSecret $clientSecret # Get all environments and find unused apps Get-AdminPowerAppEnvironment | Select-Object -ExpandProperty EnvironmentName | Get-UnusedPowerApps -UnusedDays 90 -ExportFormat CSV -ExportPath "C:\Reports\MonthlyUnusedApps.csv"
Usage Reporting
Create a dashboard of app usage by combining with other data:
$allEnvs = Get-AdminPowerAppEnvironment $results = @() foreach ($env in $allEnvs) { $envName = $env.EnvironmentName $envDisplayName = $env.DisplayName $unusedApps = Get-UnusedPowerApps -EnvironmentName $envName -IncludeAppDetails $allApps = Get-AdminPowerApp -EnvironmentName $envName $results += [PSCustomObject]@{ EnvironmentName = $envDisplayName TotalApps = $allApps.Count UnusedApps = $unusedApps.Count UsagePercentage = if ($allApps.Count -gt 0) { [math]::Round(($allApps.Count - $unusedApps.Count) / $allApps.Count * 100, 2) } else { 0 } } } $results | Export-Csv -Path "C:\Reports\AppUsageByEnvironment.csv" -NoTypeInformation
Limitations and Considerations
- The function uses LastModifiedTime as a proxy for app usage, which isn't a perfect measure of actual usage
- Role assignments check might not capture shared apps where users access via environment-level permissions
- Processing large environments may take time, especially with many apps or role assignments
- Requires admin permissions to access the environments and apps
Troubleshooting
Common Issues
-
Connection errors
- Ensure you're connected via Add-PowerAppsAccount before running
- Check your permissions on the environments
-
No data returned
- Verify the environment ID is correct
- Check if there are any apps in the environment
-
Export errors
- Ensure the specified path is writable
- Try using an absolute path instead of a relative one
Diagnostic Steps
-
Run with verbose output:
$VerbosePreference = "Continue" Get-UnusedPowerApps -EnvironmentName "your-environment-id" $VerbosePreference = "SilentlyContinue"
-
Test environment access:
Get-AdminPowerAppEnvironment -EnvironmentName "your-environment-id"
Version History
- v1.0 (March 2025): Initial release
- v1.1 (Coming soon): Add app usage analytics integration
Support
For questions, suggestions, or issues, please contact:
- Email: info@theofficelab.eu
- GitHub:
License
This script is provided under the MIT License. Feel free to modify and distribute it, but please include the original attribution.