Forum Discussion
Anonymous
6 years agoNot applicable
No Returned Data from PBI Activity Log
Hi, I am a PBI service admin, and I am trying to use PowerShell to call the PBI API and return results from the PBI Activity Log. I run the command below and it returns the expected JSON response...
NickA01
4 years agoResolver III
I see this is an old thread so hopefully you have resolves it:
I had same issue earlier this week and had to change the call to use Invoke-PowerBiRestMethod and am now getting results.
Here's my full script with comments ( I do not find writing code easy so lots of comments and it may not be the best script)
# to Do
# - Change creds to user Service Principle??
# - Change output to --Opt 1 - Write directly to DB - Stage (Nvarchar(Max) -- SP to split Json -- Write to table
# - Option 2 Write to BLOB --> ADF to read Blob and write to db.
# Login
Login-PowerBIServiceAccount
#var for output pth
$PBIEventFilePath = "D:\Repos\PbiAccAudit\"
# set var for day
$day = Get-date
#Initiate day loop $s1 -> this is yesterday
for ($s = 1; $s -le 3; $s++) {
$periodStart = $day.AddDays(-$s)
$base = $periodStart.ToString("yyyy-MM-dd")
# set hour to required format -- runs from 0 am to 9 AM --Once hr is 2 digit then no issue.
for ($h = 00 ; $h -le 23; $h++) {
if ($h -le 9 )
{ $hh = 'T0' + $h }
else { $hh = 'T' + $h }
# write-host $base
$callStart = 'startDateTime=''' + $base + $hh + ':00:00.000Z'''
$callEnd = '&endDateTime=''' + $base + $hh + ':59:59.000Z'''
## Single file per hr Path for JSON output file
# $fnStart="Activity_"+$callStart.Substring(15,10)+".Json"
# $OutoutFile=$PBIEventFilePath+$fnStart
# write-host $OutoutFile
$fileName = "Activity_" + $base + ".Json"
$OutoutFile = $PBIEventFilePath + $fileName
#build uri
$baseuri = "/admin/activityevents?"
$uriStr = $baseuri + $callStart + $callEnd
#Write-Host $uriStr
#Now set sleep to avoid write errors
# $z=0;
# Write-Host $uriStr
$a = Invoke-PowerBIRestMethod -Url $uriStr -Method Get
# use for 1 file per day If = create file || append
If ($hh -eq "T00")
{ $a | Out-File -FilePath $OutoutFile }
else { $a | Out-File -FilePath $OutoutFile -Append }
# write-host $a
# Resolve-PowerBIError -Last
}
}