@@ -20,34 +20,41 @@ function Push-BECRun {
2020 $startDate = (Get-Date ).AddDays(-7 ).ToUniversalTime()
2121 $endDate = (Get-Date )
2222 Write-Information ' Getting audit logs'
23- $auditLog = (New-ExoRequest - tenantid $TenantFilter - cmdlet ' Get-AdminAuditLogConfig' ).UnifiedAuditLogIngestionEnabled
24- $7dayslog = if ($auditLog -eq $false ) {
25- $ExtractResult = ' AuditLog is disabled. Cannot perform full analysis'
26- } else {
27- $sessionid = Get-Random - Minimum 10000 - Maximum 99999
28- $operations = @ (
29- ' Remove-MailboxPermission' ,
30- ' Add-MailboxPermission' ,
31- ' UpdateCalendarDelegation' ,
32- ' AddFolderPermissions' ,
33- ' MailboxLogin' ,
34- ' UserLoggedIn'
35- )
36- $startDate = (Get-Date ).AddDays(-7 )
37- $endDate = (Get-Date )
38- $SearchParam = @ {
39- SessionCommand = ' ReturnLargeSet'
40- Operations = $operations
41- sessionid = $sessionid
42- startDate = $startDate
43- endDate = $endDate
23+ try {
24+ $auditLog = (New-ExoRequest - tenantid $TenantFilter - cmdlet ' Get-AdminAuditLogConfig' ).UnifiedAuditLogIngestionEnabled
25+ $7dayslog = if ($auditLog -eq $false ) {
26+ $ExtractResult = ' AuditLog is disabled. Cannot perform full analysis'
27+ } else {
28+ $sessionid = Get-Random - Minimum 10000 - Maximum 99999
29+ $operations = @ (
30+ ' Remove-MailboxPermission' ,
31+ ' Add-MailboxPermission' ,
32+ ' UpdateCalendarDelegation' ,
33+ ' AddFolderPermissions' ,
34+ ' MailboxLogin' ,
35+ ' UserLoggedIn'
36+ )
37+ $startDate = (Get-Date ).AddDays(-7 )
38+ $endDate = (Get-Date )
39+ $SearchParam = @ {
40+ SessionCommand = ' ReturnLargeSet'
41+ Operations = $operations
42+ sessionid = $sessionid
43+ startDate = $startDate
44+ endDate = $endDate
45+ }
46+ do {
47+ $logsTenant = New-ExoRequest - tenantid $TenantFilter - cmdlet ' Search-unifiedAuditLog' - cmdParams $SearchParam - Anchor $Username
48+ Write-Information " Retrieved $ ( $logsTenant.count ) logs"
49+ $logsTenant
50+ } while ($LogsTenant.count % 5000 -eq 0 -and $LogsTenant.count -ne 0 )
51+ $ExtractResult = ' Successfully extracted logs from auditlog'
4452 }
45- do {
46- New-ExoRequest - tenantid $TenantFilter - cmdlet ' Search-unifiedAuditLog' - cmdParams $SearchParam - Anchor $Username
47- Write-Information " Retrieved $ ( $logsTenant.count ) logs"
48- $logsTenant
49- } while ($LogsTenant.count % 5000 -eq 0 -and $LogsTenant.count -ne 0 )
50- $ExtractResult = ' Successfully extracted logs from auditlog'
53+ } catch {
54+ $7dayslog = @ ()
55+ $CippAuditError = Get-CippException - Exception $_
56+ $ExtractResult = " Could not retrieve audit logs: $ ( $CippAuditError.NormalizedError ) "
57+ Write-LogMessage - API ' BECRun' - message " Failed to retrieve audit logs for $ ( $UserName ) : $ ( $CippAuditError.NormalizedError ) " - tenant $TenantFilter - sev Warning - LogData $CippAuditError
5158 }
5259 Write-Information ' Getting last sign-in'
5360 try {
0 commit comments