Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
justingraff88
Helper I
Helper I

Best way to run a script to pull Power BI activity

I have a powershell script to pull out Power BI activity logs and have it exporting a json into my onedrive. Now I am stuck at the best way to automate it so that I don't have to go in and hit the button to run it every day. Looking for something that will not require my device to be on. I'm guessing there is something in Power Automate but everything I've found seems to be several years old. I'm not a developer so the fact I've gotten this far is a testament to copilot.

 

Script:

 

Connect-PowerBIServiceAccount

 

#Input values before running the script:
$NbrDaysDaysToExtract = 30
$ExportFileLocation = 'C:\Users\Justin.Graff\OneDrive - Coretek\Reports\Power BI Logs'
$ExportFileName = 'PBIActivityEvents'
#--------------------------------------------

#Start with yesterday for counting back to ensure full day results are obtained:
[datetime]$DayUTC = (([datetime]::Today.ToUniversalTime()).Date).AddDays(-1)

#Suffix for file name so we know when it was written:
[string]$DateTimeFileWrittenUTCLabel = ([datetime]::Now.ToUniversalTime()).ToString("yyyyMMddHHmm")

#Loop through each of the days to be extracted (<Initilize> ; <Condition> ; <Repeat>)
For($LoopNbr=0 ; $LoopNbr -lt $NbrDaysDaysToExtract ; $LoopNbr++)
{
[datetime]$DateToExtractUTC=$DayUTC.AddDays(-$LoopNbr).ToString("yyyy-MM-dd")

[string]$DateToExtractLabel=$DateToExtractUTC.ToString("yyyy-MM-dd")

#Create full file name:
[string]$FullExportFileName = $ExportFileName + '-' + ($DateToExtractLabel -replace '-', '') + '-' + $DateTimeFileWrittenUTCLabel + '.json'

#Obtain activity events and store intermediary results:
[psobject]$Events=Get-PowerBIActivityEvent -StartDateTime ($DateToExtractLabel+'T00:00:00.000') -EndDateTime ($DateToExtractLabel+'T23:59:59.999')

#Write one file per day:
$Events | Out-File "$ExportFileLocation\$FullExportFileName"

Write-Verbose "File written: $FullExportFileName" -Verbose
}
Write-Verbose "Extract of Power BI activity events is complete." -Verbose

1 REPLY 1
lbendlin
Super User
Super User

Power Automate can't handle that workload.  Stick with Powershell, use the task scheduler, and keep that machine on and logged in.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors