You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`Get-PBIWorkspaceUsageReport.ps1` generates a comprehensive Power BI workspace and report usage report. It inventories all reports across all workspaces (including personal workspaces), correlates them with Power BI Activity Log data for up to 90 days, and produces a detailed usage analysis showing view counts and unique users per report. Outputs in CSV or JSON format.
5
+
`Get-PBIWorkspaceUsageReport.ps1` generates a comprehensive Power BI workspace and report usage report. It inventories all reports across all workspaces (including personal workspaces), correlates them with Power BI Activity Log data for the last 30 days by default (up to 90 days for Fabric/Premium capacities), and produces a detailed usage analysis showing view counts and unique users per report. Supports both Service Principal and interactive user authentication. Outputs in CSV or JSON format.
6
6
7
7
## Features
8
8
@@ -13,27 +13,62 @@
13
13
-**Stale Report Identification** - Reports with zero views are surfaced for potential cleanup
14
14
-**CSV and JSON Export** - Choose output format; JSON uses proper arrays for user lists
15
15
-**Pre-Flight Validation** - Validates PowerShell version, output directory, and write permissions before starting
16
-
-**Service Principal Auth** - Uses app registration with Power BI Admin APIs
16
+
-**Dual Authentication Modes** - Service Principal (client credentials) for automated/pipeline use, or interactive browser login via `-UseInteractiveAuth` for ad-hoc runs
17
17
18
18
## Prerequisites
19
19
20
20
### PowerShell Version
21
21
-**PowerShell 5.1 or later** (validated at runtime)
22
22
23
23
### Required Permissions
24
-
The service principal must be authorized for Power BI Admin APIs. One of:
25
-
-`Tenant.Read.All` permission in Power BI Service
26
-
-`Tenant.ReadWrite.All` permission in Power BI Service
27
24
28
-
**AND** one of the following tenant-level configurations:
29
-
- Service principal added to the **Power BI Service Admins** security group
30
-
- Tenant setting **"Allow service principals to use Power BI admin APIs"** enabled in Power BI Admin Portal
25
+
The script calls Power BI `/admin/` endpoints. Three things must all be in place:
31
26
32
-
### Azure App Registration Setup
33
-
1. Register an App in Azure AD / Entra ID
27
+
#### 1. Entra App Registration Permissions
28
+
Add the following API permissions to the app registration in [Entra ID](https://entra.microsoft.com) and grant admin consent:
29
+
30
+
| API | Permission | Type |
31
+
|-----|-----------|------|
32
+
| Power BI Service |`Tenant.Read.All`| Application |
33
+
34
+
#### 2. Fabric Admin RBAC Role (required to access Admin Portal settings)
35
+
The person configuring the Fabric tenant settings must hold the **Fabric Administrator** (or Global Administrator) role in Entra ID.
36
+
37
+
> Without this role, the [Fabric Admin Portal](https://app.powerbi.com/admin-portal/tenantSettings) tenant settings will not be accessible or editable.
38
+
39
+
To assign the role:
40
+
**Entra ID → Roles and administrators → Fabric Administrator → Add assignment**
41
+
42
+
#### 3. Fabric Admin Portal — Admin API Settings
43
+
Once you have the Fabric Administrator role, navigate to:
Scroll to the **Admin API settings** section and configure:
48
+
49
+
-**Setting:** "Service principals can access read-only admin APIs"
50
+
-**Toggle:** Enabled
51
+
-**Apply to:** Specific security groups
52
+
-**Action:** Add the security group that contains your app registration's service principal
53
+
54
+
> ⚠️ **Common confusion:** "Service principals can call Fabric public APIs" (under Developer settings) is a **different setting** that covers regular endpoints only. The `/admin/` endpoints used by this script require the **Admin API settings** toggle above.
55
+
56
+
### Azure App Registration Setup (Service Principal auth)
57
+
1. Register an App in Entra ID
34
58
2. Create a client secret
35
-
3. Add the service principal to the Power BI Service Admin group OR enable the tenant setting
36
-
4. No Graph API permissions needed — only Power BI REST API access
59
+
3. Grant `Tenant.Read.All` (Power BI Service) with admin consent
60
+
4. Add the service principal to the security group allowed in the Admin API settings above
61
+
5. No Microsoft Graph API permissions are needed — only Power BI REST API access
**Description:** App Registration (Service Principal) Client ID. Not used when `-UseInteractiveAuth` is specified.
52
87
53
88
### ClientSecret
54
89
**Type:** String
55
-
**Required:** Yes
56
-
**Description:** App Registration Client Secret. For production use, retrieve from Azure Key Vault rather than hardcoding.
90
+
**Required:** Yes *(Service Principal auth only)*
91
+
**Description:** App Registration Client Secret. For production use, retrieve from Azure Key Vault rather than hardcoding. Not used when `-UseInteractiveAuth` is specified.
92
+
93
+
### UseInteractiveAuth
94
+
**Type:** Switch
95
+
**Required:** No
96
+
**Description:** Use interactive browser login instead of a service principal client secret. Requires the `MicrosoftPowerBIMgmt` module. When specified, `ClientId` and `ClientSecret` are not needed. `TenantId` is still required.
57
97
58
98
### OutputPath
59
99
**Type:** String
@@ -71,53 +111,52 @@ The service principal must be authorized for Power BI Admin APIs. One of:
71
111
### ActivityDays
72
112
**Type:** Integer
73
113
**Required:** No
74
-
**Default:**`90`
114
+
**Default:**`30`
75
115
**Valid Range:** 1–90
76
-
**Description:** Number of days of Power BI activity history to retrieve. Maximum is 90 (Power BI API limitation).
116
+
**Description:** Number of days of Power BI activity history to retrieve. Standard Power BI audit log retains **30 days**; tenants with Fabric or Premium capacity may retain up to 90 days. Requesting dates outside the tenant's retention window returns a 400 error (skipped automatically per day).
77
117
78
118
## Usage Examples
79
119
80
-
### Example 1: Basic Report (CSV, Current Directory)
120
+
### Example 1: Interactive Auth (Recommended for Ad-Hoc Use)
> ⚠️ Only use `-ActivityDays` values above 30 if the tenant has Fabric or Premium capacity with extended audit retention. Standard tenants will see per-day failures for dates beyond 30 days (skipped automatically).
- Service principal not added to Power BI Service Admin group
191
-
- Tenant setting "Allow service principals to use Power BI admin APIs" not enabled
234
+
**Root Cause:**
235
+
The script calls `/admin/` endpoints. `Tenant.Read.All` being granted and the "Service principals can call Fabric public APIs" setting being enabled is **not sufficient** — the Admin API setting is controlled by a separate toggle.
236
+
237
+
**Resolution steps:**
238
+
239
+
**Step 1 — Verify you have Fabric Admin access to configure tenant settings:**
240
+
The person making changes must hold the **Fabric Administrator** (or Global Administrator) role.
241
+
> Entra ID → Roles and administrators → Fabric Administrator → Add assignment
242
+
243
+
**Step 2 — Enable Admin API access in the Fabric Admin Portal:**
244
+
Navigate to: **[https://app.powerbi.com/admin-portal/tenantSettings](https://app.powerbi.com/admin-portal/tenantSettings)**
245
+
246
+
Scroll to **Admin API settings** and configure:
247
+
- Enable: **"Service principals can access read-only admin APIs"**
248
+
- Set **Apply to:** Specific security groups
249
+
- Add the security group containing your app registration's service principal
192
250
193
-
**Solutions:**
194
-
1. Add the service principal to the **Power BI Administrator** role in Azure AD
195
-
2. Or, in Power BI Admin Portal → Tenant settings → Enable "Allow service principals to use Power BI admin APIs" and add the security group containing your SP
251
+
> ⚠️ **Common confusion:** "Service principals can call Fabric public APIs" (Developer settings) covers regular/public endpoints only — it does **not** grant access to `/admin/` endpoints used by this script.
196
252
197
253
### Issue: No workspaces returned
198
254
**Cause:** Insufficient Power BI admin permissions.
199
255
200
256
**Solution:** Verify the service principal has `Tenant.Read.All` in Power BI and admin API access is enabled.
201
257
202
-
### Issue: Activity log returns empty results
203
-
**Cause:**
204
-
-Activity logs only retain 90 days of data
258
+
### Issue: Activity log returns empty results or per-day failures
259
+
**Cause:**
260
+
-Standard Power BI audit log retains only **30 days** of data. Requesting dates older than 30 days returns 400 errors (the script skips those days automatically and reports a count at the end)
205
261
- Tenant may have activity logging disabled
206
262
207
-
**Solution:** Verify Power BI activity logging is enabled in the Power BI Admin Portal.
263
+
**Solution:**
264
+
- Use the default `ActivityDays 30` or explicitly pass `-ActivityDays 30` for standard tenants
265
+
- Only use higher values (up to 90) if the tenant has **Fabric or Premium capacity** with extended retention
266
+
- Verify Power BI activity logging is enabled in the Power BI Admin Portal
-**v1.0** - Initial release - Core inventory and usage correlation
241
300
-**v1.1** (2026-03-12) - Added pre-flight validation, improved error handling and authentication, Export-Data with verbose logging, and wrapped main auth in try/catch
301
+
-**v1.2.0** (2026-03-20) - Added `-UseInteractiveAuth` switch for interactive login via `MicrosoftPowerBIMgmt` module; switched activity event collection to `Get-PowerBIActivityEvent` cmdlet with client-side `ViewReport` filtering; changed default `ActivityDays` from 90 to 30 to match standard Power BI audit retention
0 commit comments