Activity logs file issue when using Power Shell!

Hi Team,

I am trying to build a report using activity logs. I am able to extract activity logs, however, these logs are not in the proper format and Power BI does not recognize this JSON file. Sometimes, the power bi service provides blank records, so I get below the pattern.

image

If I remove [] highlighted pattern with “,”, then it works fine. I am able to do the same thing in the text but not in this file attached. The below pattern works fine for text but not for this file.

image

I am unable to find any solution. Does anyone has any idea about solving this problem in Power Shell. Attached is the sample file. I will really appreciate if someone can provide solution. Thanks!

activitylogs.json (1.2 MB)

Kind Regards,
Naila

Hi @Naila

Is better use text format

Connect-PowerBIServiceAccount

#Path folder
$path = "C:\ActivityLog"

#Days, last week 7..1; last 30 days 30..1
1..1 |
foreach {
    $Date = (((Get-Date).Date).AddDays(-$_))
    $StartDate = (Get-Date -Date ($Date) -Format yyyy-MM-ddTHH:mm:ss)
    $EndDate = (Get-Date -Date ((($Date).AddDays(1)).AddMilliseconds(-1)) -Format yyyy-MM-ddTHH:mm:ss)
    
    Get-PowerBIActivityEvent -StartDateTime $StartDate -EndDateTime $EndDate | ConvertFrom-Json  | 
    Out-File -FilePath "$path\PowerBI_AudititLog_$(Get-Date -Date $Date -Format yyyyMMdd).txt"
}

This script generate one file per day.

2 Likes

Hello @Naila, just following up if the response from @jbressan help you solve your inquiry?

If not, how far did you get and what kind of help you need further? If yes, kindly mark as solution the answer that solved your query.

Hi @Naila, due to inactivity, a response on this post has been tagged as “Solution”. If you have any concern related to this topic, you can create a new thread.

Hi @jbressan,

Thank you so much for providing the solution. I had implemented this solution and it worked perfectly fine for me and I didn’t get a chance to look back at that project again :slight_smile: . I got busy with another project and could not reply. I am so sorry for that.

Thanks again for taking the time to provide this solution.

Kind Regards,
Naila

1 Like