DEV Community

Anthony Buhnerkemper
Anthony Buhnerkemper

Posted on

Govern Power Platform with PowerShell 7: Environments, DLP, Orphaned Apps and Flows

Power Platform grows fast.

One day you have a few apps. The next day you have hundreds of apps and flows, and nobody knows who owns them.

The admin center is fine for one environment. For the whole tenant, I want a CSV.

There is a catch. The Power Apps admin module only runs on Windows PowerShell 5.1. I wanted PowerShell 7.

So I built a toolkit that calls the Power Platform admin APIs straight from PowerShell 7. It runs on Windows, macOS and Linux. I shared it on GitHub.

Repo: power-platform-admin-powershell-toolkit

The problem it solves

Someone leaves the company. Their flows keep running as a deleted user, until they quietly fail.

A trial environment from last year still sits there. Nobody remembers why.

You want to block a connector in DLP. You have no idea who uses it.

Dataverse storage is almost full. Which environment is the big one?

These scripts make those checks quick and repeatable.

Highlight scripts

Get-PPOrphanedResourceReport.ps1

Finds apps and flows whose owner is deleted or disabled in Entra ID. It checks every owner once through Microsoft Graph.

./Get-PPOrphanedResourceReport.ps1
Enter fullscreen mode Exit fullscreen mode

Get-PPDlpPolicyReport.ps1

Lists every DLP policy and its Business, Non business and Blocked connectors. Most important, it flags environments with no DLP policy at all.

./Get-PPDlpPolicyReport.ps1
Enter fullscreen mode Exit fullscreen mode

Get-PPConnectorUsageReport.ps1

Every connection in every environment, with the connector tier. Premium and custom connectors stand out, so it doubles as a license check.

./Get-PPConnectorUsageReport.ps1 -PremiumOnly
Enter fullscreen mode Exit fullscreen mode

Get-PPTenantSettingsReport.ps1

Exports all tenant settings to JSON and CSV. Then it checks key settings against a simple baseline. For example, can only admins create environments?

./Get-PPTenantSettingsReport.ps1
Enter fullscreen mode Exit fullscreen mode

Other scripts cover the environment inventory, Dataverse storage per environment, app and flow inventories, a makers report, and giving orphaned apps a new owner from a CSV.

How the scripts are built

  • PowerShell 7.4 or later.
  • No Windows only modules. Sign in uses Az.Accounts, then the scripts call the admin APIs.
  • Comment based help on every script. Run Get-Help ./script.ps1 -Full.
  • Reports export to CSV.
  • Every report is read only.
  • The owner change script supports -WhatIf and -Confirm.
  • Certificate (app only) or interactive sign in.
  • No secrets in the repo. Examples use contoso.com and placeholder GUIDs.

Please test in a test tenant first. Read each script before you run it.

My usual workflow

Once a month, I run the environment inventory and clean up old trials.

Then I run the orphaned report and send it to the business. Someone has to take over those apps and flows.

Before any DLP change, I run the connector usage report. Then I can warn the right makers first.

Last, I export tenant settings and compare them with last month.

One tip. For app only runs, register your app as a Power Platform management app first. Without that step, every call returns access denied.

Getting started

Clone the repo:

git clone https://github.com/anthonybuhnerkemper/power-platform-admin-powershell-toolkit.git
cd power-platform-admin-powershell-toolkit
Enter fullscreen mode Exit fullscreen mode

Every toolkit ships the same Connect-M365Admin script. This one adds a PowerPlatform option. Dot source it, then connect.

# Interactive sign in
. ./scripts/Connect/Connect-M365Admin.ps1
Connect-M365Admin -Service PowerPlatform, Graph -Interactive

# Or app only with a certificate
$env:M365_TENANT_ID       = '00000000-0000-0000-0000-000000000000'
$env:M365_CLIENT_ID       = '00000000-0000-0000-0000-000000000000'
$env:M365_CERT_THUMBPRINT = '0000000000000000000000000000000000000000'
Connect-M365Admin -Service PowerPlatform, Graph
Enter fullscreen mode Exit fullscreen mode

Run a report, check the CSV, then call Disconnect-M365Admin when you are done. The README lists the modules and roles each script needs.

More toolkits

I have more free toolkits that use the same pattern, including entra-id-powershell-toolkit, sharepoint-online-powershell-toolkit and teams-powershell-toolkit.

You can find them all on my GitHub profile.

Feedback welcome

Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.

Top comments (0)