简体   繁体   中英

Automate the execution of a Power Shell script which connect to `Connect-ExchangeOnline`

    $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

For Connect-ExchangeOnline look at using certificate authentication see https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM