Skip to content

Instantly share code, notes, and snippets.

@SQLvariant
Created September 18, 2019 19:47
Show Gist options
  • Select an option

  • Save SQLvariant/98b80cbb92c26c2f557e7a2dcea70079 to your computer and use it in GitHub Desktop.

Select an option

Save SQLvariant/98b80cbb92c26c2f557e7a2dcea70079 to your computer and use it in GitHub Desktop.
Exports the PowerBI events from the O365 Audit Log into separate .CSV files for each of the last 90 days.
$UserCredential = Get-Credential 'your.email@somewhere.com'
90..1 |
foreach {
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
$Start=((Get-Date).Date).AddDays(-$_);
Search-UnifiedAuditLog -StartDate $Start -EndDate $Start.AddDays(1) -RecordType PowerBI -ResultSize 5000 |
Export-Csv -Path "c:\temp\PowerBIAuditLogs\PowerBIAudit_Log_$(Get-Date -Date $Start.AddDays(1) -Format yyyyMMdd).csv" -NoTypeInformation
Remove-PSSession $Session
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment