We have the following Power Shell script, to get the logs for SharePoint sites:-
Connect-ExchangeOnline
$OutputFile = ".\UnifiedAuditLog_FULL.csv"
$Today = Get-Date -Date (Get-Date -Format “yyyy-MM-dd”)
$intDays = 14
For ($i=0; $i -le $intDays; $i++){
For ($j=23; $j -ge 0; $j--){
$StartDate = ($Today.AddDays(-$i)).AddHours($j)
$EndDate = ($Today.AddDays(-$i)).AddHours($j + 1)
$Audit = Search-UnifiedAuditLog -StartDate $StartDate -EndDate $EndDate -ResultSize 5000
$ConvertAudit = $Audit | Select-Object -ExpandProperty AuditData | ConvertFrom-Json
$ConvertAudit | Select-Object CreationTime,UserId,Operation,Workload,ObjectID,SiteUrl,SourceFileName,ClientIP,UserAgent | Export-Csv $OutputFile -NoTypeInformation -Append
Write-Host $StartDate `t $Audit.Count
}
}
Disconnect-ExchangeOnline
now we can manually copy/paste the script inside Windows Power Shell windows >> login to our tenant for MFA >> and run the script.
but my question, is how we can automate the execution of this Power Shell to run daily on the background? in other words how we can login to ExchnageOnline without human interaction?
Thanks