Power BI activity logs track user interactions such as report views, dataset refreshes, workspace changes, and dashboard sharing. These logs are crucial for monitoring, compliance, and security.
This guide will walk you through how to generate Power BI activity logs using PowerShell.
Step 1: Prerequisites
1. Install the Power BI PowerShell Module
Ensure the Microsoft Power BI Management module is installed:
Install-Module MicrosoftPowerBIMgmt -Scope CurrentUser -Force
Power BI module installed!
2. Connect to Power BI Service
Authenticate using an admin account:
Connect-PowerBIServiceAccount
Authenticated successfully!
3. Verify Microsoft 365 Audit Logging Access
Ensure you have Global Admin, Compliance Admin, or Audit Reader roles in Microsoft 365.
To check if auditing is enabled:
Get-AdminAuditLogConfig | Format-List UnifiedAuditLogIngestionEnabled
If False, enable it:
Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true
Unified audit log enabled!
Step 2: Retrieve Power BI Activity Logs
Power BI activity logs are retrieved using Search-UnifiedAuditLog from Microsoft 365 Compliance Center.
1. Fetch Logs for the Last 7 Days
Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) -RecordType PowerBI
Activity logs retrieved!
2. Filter Logs by User
To retrieve logs for a specific user:
Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) -RecordType PowerBI -UserIds "user@yourdomain.com"
User activity logs retrieved!
3. Fetch Specific Power BI Activities
To filter logs for report sharing:
Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) -Operations "ShareDashboard"
Filtered logs retrieved!
Step 3: Export Power BI Activity Logs
To export logs to a CSV file:
$logs = Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) -RecordType PowerBI
$logs | Export-Csv -Path "C:\AuditLogs\PowerBIActivityLogs.csv" -NoTypeInformation
Activity logs exported!
Step 4: Automate Power BI Activity Log Retrieval
Create a PowerShell script PowerBI_Activity_Logs.ps1
:
# Connect to Power BI and Microsoft 365
Connect-PowerBIServiceAccount
Connect-ExchangeOnline -UserPrincipalName "admin@yourdomain.com"
# Retrieve Power BI activity logs
$logs = Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-1) -EndDate (Get-Date) -RecordType PowerBI
# Save logs
$logs | Export-Csv -Path "C:\AuditLogs\PowerBIActivityLogs_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation
Write-Host " Power BI activity logs saved!"
Automated activity log retrieval!
Step 5: Monitor Power BI Activity in Real Time
To continuously monitor Power BI activities, schedule the script using Task Scheduler:
- Open Task Scheduler → Create a new task.
- Set a trigger to run daily or at custom intervals.
- Add an action to run PowerShell:
powershell.exe -File "C:\Scripts\PowerBI_Activity_Logs.ps1"
Real-time monitoring enabled!