Home

PowerShell script to export Audit log search Data based on userID filter

%3CLINGO-SUB%20id%3D%22lingo-sub-326589%22%20slang%3D%22en-US%22%3EPowerShell%20script%20to%20export%20Audit%20log%20search%20Data%20based%20on%20userID%20filter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-326589%22%20slang%3D%22en-US%22%3E%3CP%3EOffice%20365%20Audit%20Log%20platform%20is%20helping%20you%20to%20monitor%20and%20control%20activities%20on%20your%20tenant.%3C%2FP%3E%0A%3CP%3EIn%20some%20case%2C%20it's%20necessary%20to%20export%20some%20user%20activity%20to%20detect%20some%20problematic%20usage.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EFROM%20WEB%20ADMIN%20SITE%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIt's%20possible%20to%20do%20that%20export%20from%20the%20dedicated%20Admin%20site%20%22Security%20%26amp%3B%20Compliance%22%3A%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fprotection.office.com%2F%3Frfr%3DAdminCenter%23%2Funifiedauditlog%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fprotection.office.com%2F%3Frfr%3DAdminCenter%23%2Funifiedauditlog%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EYou%20can%20select%20certain%20filter%20options%20to%20focus%20on%20your%20question%20based%20on%3A%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3EActivity%20type%3C%2FLI%3E%0A%3CLI%3EStart%20%26amp%3B%20End%20DateTime%3C%2FLI%3E%0A%3CLI%3EUsersID%20(email%20or%20O365%20login)%3C%2FLI%3E%0A%3CLI%3EFile%2C%20folder%2C%20url%20or%20site%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ethis%20filterset%20will%20be%20used%3A%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3Eto%20execute%20the%20search%20and%20export%20the%20resultset%20(in%20CSV%20format)%3C%2FLI%3E%0A%3CLI%3Eto%20create%20an%20alert%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20a%20lot%20of%20details%20related%20to%20that%20Audit%20Log%20usage%3A%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fsearch-the-audit-log-in-security-and-compliance%23search-the-audit-log%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fsearch-the-audit-log-in-security-and-compliance%23search-the-audit-log%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20some%20important%20restrictions%20need%20to%20be%20accepted%20before%20work%20with%20that%20solution%3A%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3E%3CSTRONG%3ENumber%20of%20lines%20(or%20Events)%20is%20limited%20to%2050%E2%80%99000%20max%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ENumber%20of%20characters%20exported%20to%20the%20AuditData%20details%20is%20restricted%20to%20the%20first%203%E2%80%99060%20chars%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EFROM%20POWERSHELL%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EBased%20on%20many%20other%20articles%20and%20blogposts%2C%20I%20wrote%20a%20dedicated%20PowerShell%20script%20like%20a%20toolkit%20you%20can%20use%20to%20connect%20directly%20Office%20365%20Audit%20Log%20system%20and%20send%20the%20filters%20you%20need%20to%20get%20the%20result%20set%20in%20memory.%3C%2FP%3E%0A%3CP%3EBased%20on%20that%20results%2C%20the%20script%20will%20directly%20extract%20the%20AuditData%20field%20and%20convert%20it%20into%20a%20CSV%20file%20with%20many%20fields%20(extracted%20form%20the%20JSON%20Format)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20PowerShell%20command%20used%20is%3A%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3E%3CSTRONG%3E%3CA%20title%3D%22Search-UnifiedAuditLog%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fexchange%2Fpolicy-and-compliance-audit%2Fsearch-unifiedauditlog%3Fview%3Dexchange-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESearch-UnifiedAuditLog%20-%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fexchange%2Fpolicy-and-compliance-audit%2Fsearch-unifiedauditlog%3Fview%3Dexchange-ps%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CPRE%3EFunction%20Split-O365AuditLogs-FromO365%20()%0A%7B%0A%20%20%20%20%23Get%20the%20content%20to%20process%0A%20Write-host%20%22%20-----------------------------------------%22%20-ForegroundColor%20Green%0A%0A%20%5Bstring%5D%24username%20%3D%20%22YourAdminAccount%40yourtenant.onmicrosoft.com%22%0A%20%5Bstring%5D%24PwdTXTPath%20%3D%20%22C%3A%5CSECUREDPWD%5CExportedPWD-%24(%24username).txt%22%0A%20%24secureStringPwd%20%3D%20ConvertTo-SecureString%20-string%20(Get-Content%20%24PwdTXTPath)%0A%20%24UserCredential%20%3D%20New-Object%20System.Management.Automation.PSCredential%20%24username%2C%20%24secureStringPwd%0A%0A%20%23This%20will%20prompt%20the%20user%20for%20credential%0A%23%20%24UserCredential%20%3D%20Get-Credential%0A%0A%20%24Session%20%3D%20New-PSSession%20-ConfigurationName%20Microsoft.Exchange%20-ConnectionUri%20https%3A%2F%2Foutlook.office365.com%2Fpowershell-LiveID%2F%20-Credential%20%24UserCredential%20-Authentication%20Basic%20-AllowRedirection%0A%20Import-PSSession%20%24Session%0A%0A%20%5BDateTime%5D%24startDate%20%3D%20%2201%2F01%2F2019%2000%3A00%22%20%23Format%3A%20mm%2Fdd%2Fyyyy%20hh%3AMM%0A%20%5BDateTime%5D%24endDate%20%3D%20%2201%2F11%2F2019%2023%3A59%22%20%23Format%3A%20mm%2Fdd%2Fyyyy%20hh%3AMM%0A%20%24SpecifiedUserIDs%20%3D%20%22Youremailtoscan%40yourtenant.com%22%2C%20%22Youremailtoscan2%40yourtenant.com%22%20%23syntax%3A%20%22%26lt%3Bvalue1%26gt%3B%22%2C%22%26lt%3Bvalue2%26gt%3B%22%2C...%22%26lt%3BvalueX%26gt%3B%22.%0A%0A%20%24scriptStart%3D(get-date)%0A%20%24sessionName%20%3D%20(get-date%20-Format%20'u')%2B'o365auditlog'%0A%20%23%20Reset%20user%20audit%20accumulator%0A%20%24aggregateResults%20%3D%20%40()%0A%20%24i%20%3D%200%20%23%20Loop%20counter%0A%20Do%20%7B%20%0A%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%2C%20%22SpecifiedUserIDs%3D%22%2C%20%24SpecifiedUserIDs%0A%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%20-UserIds%20%24SpecifiedUserIDs%0A%20%20if%20(%24currentResults.Count%20-gt%200)%0A%20%20%7B%0A%20%20%20Write-Host%20(%22%20%20Finished%20%7B3%7D%20search%20%23%7B1%7D%2C%20%7B2%7D%20records%3A%20%7B0%7D%20min%22%20-f%20%5Bmath%5D%3A%3ARound((New-TimeSpan%20-Start%20%24scriptStart).TotalMinutes%2C4)%2C%20%24i%2C%20%24currentResults.Count%2C%20%24user.UserPrincipalName%20)%0A%20%20%20%23%20Accumulate%20the%20data%0A%20%20%20%24aggregateResults%20%2B%3D%20%24currentResults%0A%20%20%20%23%20No%20need%20to%20do%20another%20query%20if%20the%20%23%20recs%20returned%20%26lt%3B1k%20-%20should%20save%20around%205-10%20sec%20per%20user%0A%20%20%20if%20(%24currentResults.Count%20-lt%201000)%0A%20%20%20%7B%0A%20%20%20%20%24currentResults%20%3D%20%40()%0A%20%20%20%7D%0A%20%20%20else%0A%20%20%20%7B%0A%20%20%20%20%24i%2B%2B%0A%20%20%20%7D%0A%20%20%7D%0A%20%7D%20Until%20(%24currentResults.Count%20-eq%200)%20%23%20---%20End%20of%20Session%20Search%20Loop%20---%20%23%0A%20%0A%20%5Bint%5D%24IntemIndex%20%3D%201%0A%20%24data%3D%40()%0A%20%20%20%20foreach%20(%24line%20in%20%24aggregateResults)%0A%20%20%20%20%7B%0A%20%20Write-host%20%22%20%20ItemIndex%3A%22%2C%20%24IntemIndex%2C%20%22-%20Creation%20Date%3A%22%2C%20%24line.CreationDate%2C%20%22-%20UserIds%3A%22%2C%20%24line.UserIds%2C%20%22-%20Operations%3A%22%2C%20%24line.Operations%0A%20%20Write-host%20%22%20%20%20%20%20%20%26gt%3B%20AuditData%3A%22%2C%20%24line.AuditData%0A%20%20%24datum%20%3D%20New-Object%20-TypeName%20PSObject%0A%20%20%24Converteddata%20%3D%20convertfrom-json%20%24line.AuditData%0A%20%20%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Id%20-Value%20%24Converteddata.Id%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20CreationTimeUTC%20-Value%20%24Converteddata.CreationTime%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20CreationTime%20-Value%20%24line.CreationDate%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Operation%20-Value%20%24Converteddata.Operation%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20OrganizationId%20-Value%20%24Converteddata.OrganizationId%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20RecordType%20-Value%20%24Converteddata.RecordType%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ResultStatus%20-Value%20%24Converteddata.ResultStatus%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20UserKey%20-Value%20%24Converteddata.UserKey%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20UserType%20-Value%20%24Converteddata.UserType%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Version%20-Value%20%24Converteddata.Version%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Workload%20-Value%20%24Converteddata.Workload%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20UserId%20-Value%20%24Converteddata.UserId%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientIPAddress%20-Value%20%24Converteddata.ClientIPAddress%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientInfoString%20-Value%20%24Converteddata.ClientInfoString%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientProcessName%20-Value%20%24Converteddata.ClientProcessName%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientVersion%20-Value%20%24Converteddata.ClientVersion%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ExternalAccess%20-Value%20%24Converteddata.ExternalAccess%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20InternalLogonType%20-Value%20%24Converteddata.InternalLogonType%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20LogonType%20-Value%20%24Converteddata.LogonType%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20LogonUserSid%20-Value%20%24Converteddata.LogonUserSid%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20MailboxGuid%20-Value%20%24Converteddata.MailboxGuid%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20MailboxOwnerSid%20-Value%20%24Converteddata.MailboxOwnerSid%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20MailboxOwnerUPN%20-Value%20%24Converteddata.MailboxOwnerUPN%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20OrganizationName%20-Value%20%24Converteddata.OrganizationName%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20OriginatingServer%20-Value%20%24Converteddata.OriginatingServer%0A%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20SessionId%20-Value%20%24Converteddata.SessionId%0A%20%0A%20%20%24data%20%2B%3D%20%24datum%0A%20%20%24IntemIndex%20%2B%3D%201%0A%20%7D%0A%20%24datestring%20%3D%20(get-date).ToString(%22yyyyMMdd-hhmm%22)%0A%20%24fileName%20%3D%20(%22C%3A%5CAuditLogs%5CCSVExport%5C%22%20%2B%20%24datestring%20%2B%20%22.csv%22)%0A%20%0A%20Write-Host%20(%22%20%26gt%3B%26gt%3B%26gt%3B%20writing%20to%20file%20%7B0%7D%22%20-f%20%24fileName)%0A%20%24data%20%7C%20Export-csv%20%24fileName%20-NoTypeInformation%0A%0A%20Remove-PSSession%20%24Session%0A%7D%0A%0ASplit-O365AuditLogs-FromO365%3C%2FPRE%3E%0A%3CP%3EYou%20can%20use%20that%20script%20as%20you%20want%20and%20adapt%20it%20with%20your%20own%20needs%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAttention%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EAuditData%20limitation%20stay%20into%20the%20PowerShell%20option%2C%20but%20it's%20a%20MS%20Support%20Bug%20known%20as%20detailed%20into%20that%20following%20posts%2C%20I%20hope%20that%20will%20be%20fixed%20soon%3A%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FOffice-365%2FIncomplete-data-from-Search-UnifiedAuditLog-cmdlet-for-AzureAD%2Ftd-p%2F240805%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FOffice-365%2FIncomplete-data-from-Search-UnifiedAuditLog-cmdlet-for-AzureAD%2Ftd-p%2F240805%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Foffice365itpros.com%2F2018%2F10%2F22%2Flonger-retention-office365-auditdata%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foffice365itpros.com%2F2018%2F10%2F22%2Flonger-retention-office365-auditdata%2F%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSTRONG%3EAdditional%20links%3A%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fangryanalyticsblog.azurewebsites.net%2Findex.php%2F2018%2F02%2F16%2Fpower-bi-audit-log-analytics-solution%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fangryanalyticsblog.azurewebsites.net%2Findex.php%2F2018%2F02%2F16%2Fpower-bi-audit-log-analytics-solution%2F%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fdetailed-properties-in-the-office-365-audit-log%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fdetailed-properties-in-the-office-365-audit-log%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fdetailed-properties-in-the-office-365-audit-log%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fdetailed-properties-in-the-office-365-audit-log%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fsearch-the-audit-log%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fsearch-the-audit-log%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKUyE59E3EFY%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKUyE59E3EFY%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Ftehnoonr%2F2018%2F01%2F26%2Fretrieving-office-365-audit-data-using-powershell%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.msdn.microsoft.com%2Ftehnoonr%2F2018%2F01%2F26%2Fretrieving-office-365-audit-data-using-powershell%2F%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Foffice365itpros.com%2F2018%2F10%2F22%2Flonger-retention-office365-auditdata%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foffice365itpros.com%2F2018%2F10%2F22%2Flonger-retention-office365-auditdata%2F%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fexchange%2Fpolicy-and-compliance-audit%2Fsearch-unifiedauditlog%3Fview%3Dexchange-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fexchange%2Fpolicy-and-compliance-audit%2Fsearch-unifiedauditlog%3Fview%3Dexchange-ps%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fwww.sherweb.com%2Fblog%2Factivity-reports-audit-logs-office-365%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.sherweb.com%2Fblog%2Factivity-reports-audit-logs-office-365%2F%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22http%3A%2F%2Falexbrassington.com%2F2016%2F03%2F03%2Fsplitting-office-365-audit-logs%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Falexbrassington.com%2F2016%2F03%2F03%2Fsplitting-office-365-audit-logs%2F%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FO365_Unified_Auditlog_parser%2F1.1%2FContent%2FO365_Unified_Auditlog_parser.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FO365_Unified_Auditlog_parser%2F1.1%2FContent%2FO365_Unified_Auditlog_parser.ps1%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22display%3A%20inline%20!important%3B%20float%3A%20none%3B%20background-color%3A%20transparent%3B%20color%3A%20%23333333%3B%20cursor%3A%20text%3B%20font-family%3A%20'SegoeUI'%2C'Lato'%2C'Helvetica%20Neue'%2CHelvetica%2CArial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%2027.42px%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3EFabrice%3C%2FSPAN%3E%20Romelard%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3EFrench%20version%3A%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%20style%3D%22list-style-position%3A%20inside%3B%22%3E%0A%3CLI%3E%3CEM%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.developpeur.org%2Ffabrice69%2Farchive%2F2019%2F01%2F28%2Foffice-365-script-powershell-pour-extraire-les-audit-log-bas-s-sur-des-filtres-fournis.aspx%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fblogs.developpeur.org%2Ffabrice69%2Farchive%2F2019%2F01%2F28%2Foffice-365-script-powershell-pour-extraire-les-audit-log-bas-s-sur-des-filtres-fournis.aspx%3C%2FA%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3C%2FUL%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-326589%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAudit%20Log%20Reports%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-328427%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20script%20to%20export%20Audit%20log%20search%20Data%20based%20on%20userID%20filter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-328427%22%20slang%3D%22en-US%22%3E%3CP%3EAfter%20discussion%20with%20different%20IT%20people%2C%20I%20improve%20the%20script%20adding%20options%20in%20the%20request%20but%20also%20managing%20the%20issue%20from%20the%20truncate%20JSON%20field.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20the%20CSV%20export%20will%20support%20this%20error%20from%20the%20JSON%20conversion%20and%20push%20the%20full%20AuditData%20field%20into%20a%20dedicated%20CSV%20field%20(AuditDataRaw).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20now%20use%20it%20as%20you%20need%20to.%3C%2FP%3E%0A%3CPRE%3EFunction%20Split-O365AuditLogs-FromO365%20()%0A%7B%0A%20%20%20%20%23Get%20the%20content%20to%20process%0A%20Write-host%20%22%20-----------------------------------------%22%20-ForegroundColor%20Green%0A%0A%26lt%3B%23%0A%20%5Bstring%5D%24username%20%3D%20%22AdminAccount%40yourtenant.com%22%0A%20%5Bstring%5D%24PwdTXTPath%20%3D%20%22C%3A%5CSECUREDPWD%5CExportedPWD-%24(%24username).txt%22%0A%20%24secureStringPwd%20%3D%20ConvertTo-SecureString%20-string%20(Get-Content%20%24PwdTXTPath)%0A%20%24UserCredential%20%3D%20New-Object%20System.Management.Automation.PSCredential%20%24username%2C%20%24secureStringPwd%0A%23%26gt%3B%0A%20%23This%20will%20prompt%20the%20user%20for%20credential%0A%20%24UserCredential%20%3D%20Get-Credential%0A%0A%20%24Session%20%3D%20New-PSSession%20-ConfigurationName%20Microsoft.Exchange%20-ConnectionUri%20https%3A%2F%2Foutlook.office365.com%2Fpowershell-LiveID%2F%20-Credential%20%24UserCredential%20-Authentication%20Basic%20-AllowRedirection%0A%20Import-PSSession%20%24Session%0A%0A%20%5Bbool%5D%24specifyPeriod%20%3D%20%24true%20%23%20if%20false%20it%20will%20be%20the%20default%20period%20time%20specified%20%24DefaultPeriodToCheck%20(last%20XX%20days)%0A%20%5Bint%5D%24DefaultPeriodToCheck%20%3D%20-7%20%23last%207%20days%20by%20default%0A%20%5BDateTime%5D%24startDate%20%3D%20%2201%2F01%2F2019%2000%3A00%22%20%23%2201%2F01%2F2019%2000%3A00%22%20%23Format%3A%20mm%2Fdd%2Fyyyy%20hh%3AMM%20%23(get-date).AddDays(-1)%0A%20%5BDateTime%5D%24endDate%20%3D%20%2201%2F31%2F2019%2023%3A59%22%20%23%2201%2F11%2F2019%2023%3A59%22%20%23Format%3A%20mm%2Fdd%2Fyyyy%20hh%3AMM%20%23(get-date)%0A%20%0A%20%5Bbool%5D%24specifyUserIDs%20%3D%20%24false%0A%20%24SpecifiedUserIDs%20%3D%20%22UserIdEmailAddress%40yourtenant.com%22%20%23syntax%3A%20%22%26lt%3Bvalue1%26gt%3B%22%2C%22%26lt%3Bvalue2%26gt%3B%22%2C...%22%26lt%3BvalueX%26gt%3B%22%0A%20%0A%20%5Bbool%5D%24specifyRecordTypes%20%3D%20%24false%0A%20%24RecordTypeValues%20%3D%20%22SharePoint%22%20%23Only%20one%20field%20to%20put%2C%20biggest%20products%3A%20%22OneDrive%22%20%22SharePoint%22%20%22Sway%22%20%22PowerBI%22%20%22MicrosoftTeams%22%20%22MicrosoftStream%22%0A%20%23%20Possible%20values%3A%20%26lt%3BExchangeAdmin%20%7C%20ExchangeItem%20%7C%20ExchangeItemGroup%20%7C%20SharePoint%20%7C%20SyntheticProbe%20%7C%20SharePointFileOperation%20%7C%20OneDrive%20%7C%20AzureActiveDirectory%20%7C%20AzureActiveDirectoryAccountLogon%20%7C%20DataCenterSecurityCmdlet%20%7C%20ComplianceDLPSharePoint%20%7C%20Sway%20%7C%20ComplianceDLPExchange%20%7C%20SharePointSharingOperation%20%7C%20AzureActiveDirectoryStsLogon%20%7C%20SkypeForBusinessPSTNUsage%20%7C%20SkypeForBusinessUsersBlocked%20%7C%20SecurityComplianceCenterEOPCmdlet%20%7C%20ExchangeAggregatedOperation%20%7C%20PowerBIAudit%20%7C%20CRM%20%7C%20Yammer%20%7C%20SkypeForBusinessCmdlets%20%7C%20Discovery%20%7C%20MicrosoftTeams%20%7C%20MicrosoftTeamsAddOns%20%7C%20MicrosoftTeamsSettingsOperation%20%7C%20ThreatIntelligence%20AeD%2C%20MicrosoftStream%2C%20ThreatFinder%2C%20Project%2C%20SharePointListOperation%2C%20DataGovernance%2C%20SecurityComplianceAlerts%2C%20ThreatIntelligenceUrl%2C%20SecurityComplianceInsights%2C%20WorkplaceAnalytics%2C%20PowerAppsApp%2C%20PowerAppsPlan%2C%20ThreatIntelligenceAtpContent%2C%20LabelExplorer%2C%20TeamsHealthcare%2C%20ExchangeItemAggregated%2C%20HygieneEvent%26gt%3B%0A%20%0A%20%0A%20%24scriptStart%3D(get-date)%0A%0A%20%24sessionName%20%3D%20(get-date%20-Format%20'u')%2B'o365auditlog'%0A%20%23%20Reset%20user%20audit%20accumulator%0A%20%24aggregateResults%20%3D%20%40()%0A%20%24i%20%3D%200%20%23%20Loop%20counter%0A%20Do%20%7B%20%0A%20%20Write-host%20%22%20-----------------------------------------%22%20-ForegroundColor%20Yellow%0A%20%20if(%24specifyPeriod%20-eq%20%24true)%0A%20%20%7B%0A%20%20%20if(%24specifyUserIDs%20-eq%20%24true)%0A%20%20%20%7B%0A%20%20%20%20if%20(%24specifyRecordTypes%20-eq%20%24true)%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%2C%20%22-%20SpecifiedUserIDs%3D%22%2C%20%24SpecifiedUserIDs%2C%20%22-%20RecordType%3D%22%2C%20%24RecordTypeValues%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%20-UserIds%20%24SpecifiedUserIDs%20-RecordType%20%24RecordTypeValues%0A%20%20%20%20%7D%0A%20%20%20%20else%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%2C%20%22-%20SpecifiedUserIDs%3D%22%2C%20%24SpecifiedUserIDs%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%20-UserIds%20%24SpecifiedUserIDs%0A%20%20%20%20%7D%0A%20%20%20%7D%0A%20%20%20else%0A%20%20%20%7B%0A%20%20%20%20if%20(%24specifyRecordTypes%20-eq%20%24true)%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%2C%20%22-%20RecordType%3D%22%2C%20%24RecordTypeValues%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%20-RecordType%20%24RecordTypeValues%0A%20%20%20%20%7D%0A%20%20%20%20else%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%0A%20%20%20%20%7D%0A%20%20%20%7D%0A%20%20%7D%0A%20%20else%0A%20%20%7B%0A%20%20%20%24enddate%20%3D%20get-date%0A%20%20%20%24startDate%20%3D%20%24enddate.AddDays(%24DefaultPeriodToCheck)%20%23default%20period%20is%20the%20last%20week%0A%20%20%20if(%24specifyUserIDs%20-eq%20%24true)%0A%20%20%20%7B%0A%20%20%20%20if%20(%24specifyRecordTypes%20-eq%20%24true)%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%2C%20%22-%20SpecifiedUserIDs%3D%22%2C%20%24SpecifiedUserIDs%2C%20%22-%20RecordType%3D%22%2C%20%24RecordTypeValues%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%20-UserIds%20%24SpecifiedUserIDs%20-RecordType%20%24RecordTypeValues%0A%20%20%20%20%7D%0A%20%20%20%20else%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%2C%20%22-%20SpecifiedUserIDs%3D%22%2C%20%24SpecifiedUserIDs%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%20-UserIds%20%24SpecifiedUserIDs%0A%20%20%20%20%7D%0A%20%20%20%7D%0A%20%20%20else%0A%20%20%20%7B%0A%20%20%20%20if%20(%24specifyRecordTypes%20-eq%20%24true)%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%2C%20%22-%20RecordType%3D%22%2C%20%24RecordTypeValues%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%20-RecordType%20%24RecordTypeValues%0A%20%20%20%20%7D%0A%20%20%20%20else%0A%20%20%20%20%7B%0A%20%20%20%20%20Write-host%20%22%20%20%26gt%3B%26gt%3B%20Audit%20Request%20Details%3A%20StartDate%3D%22%2C%20%24startDate%2C%20%22-%20EndDate%3D%22%2C%20%24endDate%20-ForegroundColor%20Magenta%0A%20%20%20%20%20%24currentResults%20%3D%20Search-UnifiedAuditLog%20-StartDate%20%24startDate%20-EndDate%20%24enddate%20-SessionId%20%24sessionName%20-SessionCommand%20ReturnLargeSet%20-ResultSize%201000%0A%20%20%20%20%7D%0A%20%20%20%0A%20%20%20%7D%0A%20%20%7D%0A%20%20%0A%20%20if%20(%24currentResults.Count%20-gt%200)%0A%20%20%7B%0A%20%20%20Write-Host%20(%22%20%20Finished%20%7B3%7D%20search%20%23%7B1%7D%2C%20%7B2%7D%20records%3A%20%7B0%7D%20min%22%20-f%20%5Bmath%5D%3A%3ARound((New-TimeSpan%20-Start%20%24scriptStart).TotalMinutes%2C4)%2C%20%24i%2C%20%24currentResults.Count%2C%20%24user.UserPrincipalName%20)%0A%20%20%20%23%20Accumulate%20the%20data%0A%20%20%20%24aggregateResults%20%2B%3D%20%24currentResults%0A%20%20%20%23%20No%20need%20to%20do%20another%20query%20if%20the%20%23%20recs%20returned%20%26lt%3B1k%20-%20should%20save%20around%205-10%20sec%20per%20user%0A%20%20%20if%20(%24currentResults.Count%20-lt%201000)%0A%20%20%20%7B%0A%20%20%20%20%24currentResults%20%3D%20%40()%0A%20%20%20%7D%0A%20%20%20else%0A%20%20%20%7B%0A%20%20%20%20%24i%2B%2B%0A%20%20%20%7D%0A%20%20%7D%0A%20%7D%20Until%20(%24currentResults.Count%20-eq%200)%20%23%20---%20End%20of%20Session%20Search%20Loop%20---%20%23%0A%20%0A%20%5Bint%5D%24IntemIndex%20%3D%201%0A%20%24data%3D%40()%0A%20%20%20%20foreach%20(%24line%20in%20%24aggregateResults)%0A%20%20%20%20%7B%0A%20%20Write-host%20%22%20%20ItemIndex%3A%22%2C%20%24IntemIndex%2C%20%22-%20Creation%20Date%3A%22%2C%20%24line.CreationDate%2C%20%22-%20UserIds%3A%22%2C%20%24line.UserIds%2C%20%22-%20Operations%3A%22%2C%20%24line.Operations%0A%20%20%23Write-host%20%22%20%20%20%20%20%20%26gt%3B%20AuditData%3A%22%2C%20%24line.AuditData%0A%20%20%24datum%20%3D%20New-Object%20-TypeName%20PSObject%0A%20%20try%0A%20%20%7B%0A%20%20%20%24Converteddata%20%3D%20convertfrom-json%20%24line.AuditData%0A%20%20%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Id%20-Value%20%24Converteddata.Id%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20CreationTimeUTC%20-Value%20%24Converteddata.CreationTime%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20CreationTime%20-Value%20%24line.CreationDate%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Operation%20-Value%20%24Converteddata.Operation%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20OrganizationId%20-Value%20%24Converteddata.OrganizationId%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20RecordType%20-Value%20%24Converteddata.RecordType%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ResultStatus%20-Value%20%24Converteddata.ResultStatus%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20UserKey%20-Value%20%24Converteddata.UserKey%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20UserType%20-Value%20%24Converteddata.UserType%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Version%20-Value%20%24Converteddata.Version%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Workload%20-Value%20%24Converteddata.Workload%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20UserId%20-Value%20%24Converteddata.UserId%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientIPAddress%20-Value%20%24Converteddata.ClientIPAddress%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientInfoString%20-Value%20%24Converteddata.ClientInfoString%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientProcessName%20-Value%20%24Converteddata.ClientProcessName%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ClientVersion%20-Value%20%24Converteddata.ClientVersion%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ExternalAccess%20-Value%20%24Converteddata.ExternalAccess%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20InternalLogonType%20-Value%20%24Converteddata.InternalLogonType%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20LogonType%20-Value%20%24Converteddata.LogonType%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20LogonUserSid%20-Value%20%24Converteddata.LogonUserSid%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20MailboxGuid%20-Value%20%24Converteddata.MailboxGuid%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20MailboxOwnerSid%20-Value%20%24Converteddata.MailboxOwnerSid%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20MailboxOwnerUPN%20-Value%20%24Converteddata.MailboxOwnerUPN%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20OrganizationName%20-Value%20%24Converteddata.OrganizationName%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20OriginatingServer%20-Value%20%24Converteddata.OriginatingServer%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20SessionId%20-Value%20%24Converteddata.SessionId%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20LogonError%20-Value%20%24Converteddata.LogonError%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Subject%20-Value%20%24Converteddata.Subject%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20ObjectId%20-Value%20%24Converteddata.ObjectId%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20SiteUrl%20-Value%20%24Converteddata.SiteUrl%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20SourceRelativeUrl%20-Value%20%24Converteddata.SourceRelativeUrl%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20AuditDataRaw%20-Value%20%24line.AuditData%0A%20%20%7D%0A%20%20catch%0A%20%20%7B%0A%20%20%20Write-host%20%22%20%20%3D%3D%3D%3D%3D%26gt%3B%26gt%3B%26gt%3B%26gt%3B%20JSON%20FORMAT%20NOT%20CORRECT%20%22%20-ForegroundColor%20Red%0A%20%20%20Write-host%20%22%20%20%3D%3D%3D%3D%3D%26gt%3B%26gt%3B%26gt%3B%26gt%3B%20AuditData%3A%22%2C%20%24line.AuditData%20%20-ForegroundColor%20Yellow%0A%20%20%20%5Bguid%5D%24NewGuid%20%3D%20%5Bguid%5D%3A%3Anewguid()%20%20%20%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Id%20-Value%20%24NewGuid%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20CreationTimeUTC%20-Value%20%24line.CreationDate%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20CreationTime%20-Value%20%24line.CreationDate%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20UserId%20-Value%20%24line.UserIds%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20Operation%20-Value%20%24line.Operations%0A%20%20%20%24datum%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20AuditDataRaw%20-Value%20%24line.AuditData%0A%20%20%7D%0A%20%0A%20%20%24data%20%2B%3D%20%24datum%0A%20%20%24IntemIndex%20%2B%3D%201%0A%20%7D%0A%20%24datestring%20%3D%20(get-date).ToString(%22yyyyMMdd-hhmm%22)%0A%20%24fileName%20%3D%20(%22C%3A%5CAuditLogs%5CCSVExport%5C%22%20%2B%20%24datestring%20%2B%20%22.csv%22)%0A%20%0A%20Write-host%20%22%20-----------------------------------------%22%20-ForegroundColor%20Green%0A%20Write-Host%20(%22%20%26gt%3B%26gt%3B%26gt%3B%20writing%20to%20file%20%7B0%7D%22%20-f%20%24fileName)%20-ForegroundColor%20Green%0A%20%24data%20%7C%20Export-csv%20%24fileName%20-NoTypeInformation%0A%20Write-host%20%22%20-----------------------------------------%22%20-ForegroundColor%20Green%0A%0A%20Remove-PSSession%20%24Session%0A%7D%0Acls%0ASplit-O365AuditLogs-FromO365%3C%2FPRE%3E%0A%3CP%3EEnjoy%20your%20day.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFabrice%20Romelard%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

Office 365 Audit Log platform is helping you to monitor and control activities on your tenant.

In some case, it's necessary to export some user activity to detect some problematic usage.

 

FROM WEB ADMIN SITE

It's possible to do that export from the dedicated Admin site "Security & Compliance":

You can select certain filter options to focus on your question based on:

  • Activity type
  • Start & End DateTime
  • UsersID (email or O365 login)
  • File, folder, url or site

 

this filterset will be used:

  • to execute the search and export the resultset (in CSV format)
  • to create an alert

 

You can find a lot of details related to that Audit Log usage:

 

But some important restrictions need to be accepted before work with that solution:

  • Number of lines (or Events) is limited to 50’000 max
  • Number of characters exported to the AuditData details is restricted to the first 3’060 chars

 

FROM POWERSHELL

Based on many other articles and blogposts, I wrote a dedicated PowerShell script like a toolkit you can use to connect directly Office 365 Audit Log system and send the filters you need to get the result set in memory.

Based on that results, the script will directly extract the AuditData field and convert it into a CSV file with many fields (extracted form the JSON Format)

 

The PowerShell command used is:

Function Split-O365AuditLogs-FromO365 ()
{
    #Get the content to process
	Write-host " -----------------------------------------" -ForegroundColor Green

	[string]$username = "YourAdminAccount@yourtenant.onmicrosoft.com"
	[string]$PwdTXTPath = "C:\SECUREDPWD\ExportedPWD-$($username).txt"
	$secureStringPwd = ConvertTo-SecureString -string (Get-Content $PwdTXTPath)
	$UserCredential = New-Object System.Management.Automation.PSCredential $username, $secureStringPwd

	#This will prompt the user for credential
#	$UserCredential = Get-Credential

	$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-LiveID/ -Credential $UserCredential -Authentication Basic -AllowRedirection
	Import-PSSession $Session

	[DateTime]$startDate = "01/01/2019 00:00" #Format: mm/dd/yyyy hh:MM
	[DateTime]$endDate = "01/11/2019 23:59" #Format: mm/dd/yyyy hh:MM
	$SpecifiedUserIDs = "Youremailtoscan@yourtenant.com", "Youremailtoscan2@yourtenant.com" #syntax: "<value1>","<value2>",..."<valueX>".

	$scriptStart=(get-date)
	$sessionName = (get-date -Format 'u')+'o365auditlog'
	# Reset user audit accumulator
	$aggregateResults = @()
	$i = 0 # Loop counter
	Do { 
		Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "SpecifiedUserIDs=", $SpecifiedUserIDs
		$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -UserIds $SpecifiedUserIDs
		if ($currentResults.Count -gt 0)
		{
			Write-Host ("  Finished {3} search #{1}, {2} records: {0} min" -f [math]::Round((New-TimeSpan -Start $scriptStart).TotalMinutes,4), $i, $currentResults.Count, $user.UserPrincipalName )
			# Accumulate the data
			$aggregateResults += $currentResults
			# No need to do another query if the # recs returned <1k - should save around 5-10 sec per user
			if ($currentResults.Count -lt 1000)
			{
				$currentResults = @()
			}
			else
			{
				$i++
			}
		}
	} Until ($currentResults.Count -eq 0) # --- End of Session Search Loop --- #
	
	[int]$IntemIndex = 1
	$data=@()
    foreach ($line in $aggregateResults)
    {
		Write-host "  ItemIndex:", $IntemIndex, "- Creation Date:", $line.CreationDate, "- UserIds:", $line.UserIds, "- Operations:", $line.Operations
		Write-host "      > AuditData:", $line.AuditData
		$datum = New-Object -TypeName PSObject
		$Converteddata = convertfrom-json $line.AuditData
		
		$datum | Add-Member -MemberType NoteProperty -Name Id -Value $Converteddata.Id
		$datum | Add-Member -MemberType NoteProperty -Name CreationTimeUTC -Value $Converteddata.CreationTime
		$datum | Add-Member -MemberType NoteProperty -Name CreationTime -Value $line.CreationDate
		$datum | Add-Member -MemberType NoteProperty -Name Operation -Value $Converteddata.Operation
		$datum | Add-Member -MemberType NoteProperty -Name OrganizationId -Value $Converteddata.OrganizationId
		$datum | Add-Member -MemberType NoteProperty -Name RecordType -Value $Converteddata.RecordType
		$datum | Add-Member -MemberType NoteProperty -Name ResultStatus -Value $Converteddata.ResultStatus
		$datum | Add-Member -MemberType NoteProperty -Name UserKey -Value $Converteddata.UserKey
		$datum | Add-Member -MemberType NoteProperty -Name UserType -Value $Converteddata.UserType
		$datum | Add-Member -MemberType NoteProperty -Name Version -Value $Converteddata.Version
		$datum | Add-Member -MemberType NoteProperty -Name Workload -Value $Converteddata.Workload
		$datum | Add-Member -MemberType NoteProperty -Name UserId -Value $Converteddata.UserId
		$datum | Add-Member -MemberType NoteProperty -Name ClientIPAddress -Value $Converteddata.ClientIPAddress
		$datum | Add-Member -MemberType NoteProperty -Name ClientInfoString -Value $Converteddata.ClientInfoString
		$datum | Add-Member -MemberType NoteProperty -Name ClientProcessName -Value $Converteddata.ClientProcessName
		$datum | Add-Member -MemberType NoteProperty -Name ClientVersion -Value $Converteddata.ClientVersion
		$datum | Add-Member -MemberType NoteProperty -Name ExternalAccess -Value $Converteddata.ExternalAccess
		$datum | Add-Member -MemberType NoteProperty -Name InternalLogonType -Value $Converteddata.InternalLogonType
		$datum | Add-Member -MemberType NoteProperty -Name LogonType -Value $Converteddata.LogonType
		$datum | Add-Member -MemberType NoteProperty -Name LogonUserSid -Value $Converteddata.LogonUserSid
		$datum | Add-Member -MemberType NoteProperty -Name MailboxGuid -Value $Converteddata.MailboxGuid
		$datum | Add-Member -MemberType NoteProperty -Name MailboxOwnerSid -Value $Converteddata.MailboxOwnerSid
		$datum | Add-Member -MemberType NoteProperty -Name MailboxOwnerUPN -Value $Converteddata.MailboxOwnerUPN
		$datum | Add-Member -MemberType NoteProperty -Name OrganizationName -Value $Converteddata.OrganizationName
		$datum | Add-Member -MemberType NoteProperty -Name OriginatingServer -Value $Converteddata.OriginatingServer
		$datum | Add-Member -MemberType NoteProperty -Name SessionId -Value $Converteddata.SessionId
	
		$data += $datum
		$IntemIndex += 1
	}
	$datestring = (get-date).ToString("yyyyMMdd-hhmm")
	$fileName = ("C:\AuditLogs\CSVExport\" + $datestring + ".csv")
	
	Write-Host (" >>> writing to file {0}" -f $fileName)
	$data | Export-csv $fileName -NoTypeInformation

	Remove-PSSession $Session
}

Split-O365AuditLogs-FromO365

You can use that script as you want and adapt it with your own needs

 

Attention:

AuditData limitation stay into the PowerShell option, but it's a MS Support Bug known as detailed into that following posts, I hope that will be fixed soon:

 

 

Additional links:


Fabrice Romelard

 

French version:

In this webinar, Randy Franklin Smith, Windows Security subject matter expert, and Bruce Deakyne, technical product manager at LogRhythm, introduce you to Office 365 Unified Audit Logging. Office 365 offers a limited web portal where you can search and access audit events online. The duo briefly ...
1 Reply

After discussion with different IT people, I improve the script adding options in the request but also managing the issue from the truncate JSON field.

 

Now the CSV export will support this error from the JSON conversion and push the full AuditData field into a dedicated CSV field (AuditDataRaw).

 

You can now use it as you need to.

Function Split-O365AuditLogs-FromO365 ()
{
    #Get the content to process
	Write-host " -----------------------------------------" -ForegroundColor Green

<#
	[string]$username = "AdminAccount@yourtenant.com"
	[string]$PwdTXTPath = "C:\SECUREDPWD\ExportedPWD-$($username).txt"
	$secureStringPwd = ConvertTo-SecureString -string (Get-Content $PwdTXTPath)
	$UserCredential = New-Object System.Management.Automation.PSCredential $username, $secureStringPwd
#>
	#This will prompt the user for credential
	$UserCredential = Get-Credential

	$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-LiveID/ -Credential $UserCredential -Authentication Basic -AllowRedirection
	Import-PSSession $Session

	[bool]$specifyPeriod = $true # if false it will be the default period time specified $DefaultPeriodToCheck (last XX days)
	[int]$DefaultPeriodToCheck = -7 #last 7 days by default
	[DateTime]$startDate = "01/01/2019 00:00" #"01/01/2019 00:00" #Format: mm/dd/yyyy hh:MM #(get-date).AddDays(-1)
	[DateTime]$endDate = "01/31/2019 23:59" #"01/11/2019 23:59" #Format: mm/dd/yyyy hh:MM #(get-date)
	
	[bool]$specifyUserIDs = $false
	$SpecifiedUserIDs = "UserIdEmailAddress@yourtenant.com" #syntax: "<value1>","<value2>",..."<valueX>"
	
	[bool]$specifyRecordTypes = $false
	$RecordTypeValues = "SharePoint" #Only one field to put, biggest products: "OneDrive" "SharePoint" "Sway" "PowerBI" "MicrosoftTeams" "MicrosoftStream"
	# Possible values: <ExchangeAdmin | ExchangeItem | ExchangeItemGroup | SharePoint | SyntheticProbe | SharePointFileOperation | OneDrive | AzureActiveDirectory | AzureActiveDirectoryAccountLogon | DataCenterSecurityCmdlet | ComplianceDLPSharePoint | Sway | ComplianceDLPExchange | SharePointSharingOperation | AzureActiveDirectoryStsLogon | SkypeForBusinessPSTNUsage | SkypeForBusinessUsersBlocked | SecurityComplianceCenterEOPCmdlet | ExchangeAggregatedOperation | PowerBIAudit | CRM | Yammer | SkypeForBusinessCmdlets | Discovery | MicrosoftTeams | MicrosoftTeamsAddOns | MicrosoftTeamsSettingsOperation | ThreatIntelligence AeD, MicrosoftStream, ThreatFinder, Project, SharePointListOperation, DataGovernance, SecurityComplianceAlerts, ThreatIntelligenceUrl, SecurityComplianceInsights, WorkplaceAnalytics, PowerAppsApp, PowerAppsPlan, ThreatIntelligenceAtpContent, LabelExplorer, TeamsHealthcare, ExchangeItemAggregated, HygieneEvent>
	
	
	$scriptStart=(get-date)

	$sessionName = (get-date -Format 'u')+'o365auditlog'
	# Reset user audit accumulator
	$aggregateResults = @()
	$i = 0 # Loop counter
	Do { 
		Write-host " -----------------------------------------" -ForegroundColor Yellow
		if($specifyPeriod -eq $true)
		{
			if($specifyUserIDs -eq $true)
			{
				if ($specifyRecordTypes -eq $true)
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "- SpecifiedUserIDs=", $SpecifiedUserIDs, "- RecordType=", $RecordTypeValues -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -UserIds $SpecifiedUserIDs -RecordType $RecordTypeValues
				}
				else
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "- SpecifiedUserIDs=", $SpecifiedUserIDs -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -UserIds $SpecifiedUserIDs
				}
			}
			else
			{
				if ($specifyRecordTypes -eq $true)
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "- RecordType=", $RecordTypeValues -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -RecordType $RecordTypeValues
				}
				else
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000
				}
			}
		}
		else
		{
			$enddate = get-date
			$startDate = $enddate.AddDays($DefaultPeriodToCheck) #default period is the last week
			if($specifyUserIDs -eq $true)
			{
				if ($specifyRecordTypes -eq $true)
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "- SpecifiedUserIDs=", $SpecifiedUserIDs, "- RecordType=", $RecordTypeValues -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -UserIds $SpecifiedUserIDs -RecordType $RecordTypeValues
				}
				else
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "- SpecifiedUserIDs=", $SpecifiedUserIDs -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -UserIds $SpecifiedUserIDs
				}
			}
			else
			{
				if ($specifyRecordTypes -eq $true)
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "- RecordType=", $RecordTypeValues -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -RecordType $RecordTypeValues
				}
				else
				{
					Write-host "  >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate -ForegroundColor Magenta
					$currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000
				}
			
			}
		}
		
		if ($currentResults.Count -gt 0)
		{
			Write-Host ("  Finished {3} search #{1}, {2} records: {0} min" -f [math]::Round((New-TimeSpan -Start $scriptStart).TotalMinutes,4), $i, $currentResults.Count, $user.UserPrincipalName )
			# Accumulate the data
			$aggregateResults += $currentResults
			# No need to do another query if the # recs returned <1k - should save around 5-10 sec per user
			if ($currentResults.Count -lt 1000)
			{
				$currentResults = @()
			}
			else
			{
				$i++
			}
		}
	} Until ($currentResults.Count -eq 0) # --- End of Session Search Loop --- #
	
	[int]$IntemIndex = 1
	$data=@()
    foreach ($line in $aggregateResults)
    {
		Write-host "  ItemIndex:", $IntemIndex, "- Creation Date:", $line.CreationDate, "- UserIds:", $line.UserIds, "- Operations:", $line.Operations
		#Write-host "      > AuditData:", $line.AuditData
		$datum = New-Object -TypeName PSObject
		try
		{
			$Converteddata = convertfrom-json $line.AuditData
		
			$datum | Add-Member -MemberType NoteProperty -Name Id -Value $Converteddata.Id
			$datum | Add-Member -MemberType NoteProperty -Name CreationTimeUTC -Value $Converteddata.CreationTime
			$datum | Add-Member -MemberType NoteProperty -Name CreationTime -Value $line.CreationDate
			$datum | Add-Member -MemberType NoteProperty -Name Operation -Value $Converteddata.Operation
			$datum | Add-Member -MemberType NoteProperty -Name OrganizationId -Value $Converteddata.OrganizationId
			$datum | Add-Member -MemberType NoteProperty -Name RecordType -Value $Converteddata.RecordType
			$datum | Add-Member -MemberType NoteProperty -Name ResultStatus -Value $Converteddata.ResultStatus
			$datum | Add-Member -MemberType NoteProperty -Name UserKey -Value $Converteddata.UserKey
			$datum | Add-Member -MemberType NoteProperty -Name UserType -Value $Converteddata.UserType
			$datum | Add-Member -MemberType NoteProperty -Name Version -Value $Converteddata.Version
			$datum | Add-Member -MemberType NoteProperty -Name Workload -Value $Converteddata.Workload
			$datum | Add-Member -MemberType NoteProperty -Name UserId -Value $Converteddata.UserId
			$datum | Add-Member -MemberType NoteProperty -Name ClientIPAddress -Value $Converteddata.ClientIPAddress
			$datum | Add-Member -MemberType NoteProperty -Name ClientInfoString -Value $Converteddata.ClientInfoString
			$datum | Add-Member -MemberType NoteProperty -Name ClientProcessName -Value $Converteddata.ClientProcessName
			$datum | Add-Member -MemberType NoteProperty -Name ClientVersion -Value $Converteddata.ClientVersion
			$datum | Add-Member -MemberType NoteProperty -Name ExternalAccess -Value $Converteddata.ExternalAccess
			$datum | Add-Member -MemberType NoteProperty -Name InternalLogonType -Value $Converteddata.InternalLogonType
			$datum | Add-Member -MemberType NoteProperty -Name LogonType -Value $Converteddata.LogonType
			$datum | Add-Member -MemberType NoteProperty -Name LogonUserSid -Value $Converteddata.LogonUserSid
			$datum | Add-Member -MemberType NoteProperty -Name MailboxGuid -Value $Converteddata.MailboxGuid
			$datum | Add-Member -MemberType NoteProperty -Name MailboxOwnerSid -Value $Converteddata.MailboxOwnerSid
			$datum | Add-Member -MemberType NoteProperty -Name MailboxOwnerUPN -Value $Converteddata.MailboxOwnerUPN
			$datum | Add-Member -MemberType NoteProperty -Name OrganizationName -Value $Converteddata.OrganizationName
			$datum | Add-Member -MemberType NoteProperty -Name OriginatingServer -Value $Converteddata.OriginatingServer
			$datum | Add-Member -MemberType NoteProperty -Name SessionId -Value $Converteddata.SessionId
			$datum | Add-Member -MemberType NoteProperty -Name LogonError -Value $Converteddata.LogonError
			$datum | Add-Member -MemberType NoteProperty -Name Subject -Value $Converteddata.Subject
			$datum | Add-Member -MemberType NoteProperty -Name ObjectId -Value $Converteddata.ObjectId
			$datum | Add-Member -MemberType NoteProperty -Name SiteUrl -Value $Converteddata.SiteUrl
			$datum | Add-Member -MemberType NoteProperty -Name SourceRelativeUrl -Value $Converteddata.SourceRelativeUrl
			$datum | Add-Member -MemberType NoteProperty -Name AuditDataRaw -Value $line.AuditData
		}
		catch
		{
			Write-host "  =====>>>> JSON FORMAT NOT CORRECT " -ForegroundColor Red
			Write-host "  =====>>>> AuditData:", $line.AuditData  -ForegroundColor Yellow
			[guid]$NewGuid = [guid]::newguid()			
			$datum | Add-Member -MemberType NoteProperty -Name Id -Value $NewGuid
			$datum | Add-Member -MemberType NoteProperty -Name CreationTimeUTC -Value $line.CreationDate
			$datum | Add-Member -MemberType NoteProperty -Name CreationTime -Value $line.CreationDate
			$datum | Add-Member -MemberType NoteProperty -Name UserId -Value $line.UserIds
			$datum | Add-Member -MemberType NoteProperty -Name Operation -Value $line.Operations
			$datum | Add-Member -MemberType NoteProperty -Name AuditDataRaw -Value $line.AuditData
		}
	
		$data += $datum
		$IntemIndex += 1
	}
	$datestring = (get-date).ToString("yyyyMMdd-hhmm")
	$fileName = ("C:\AuditLogs\CSVExport\" + $datestring + ".csv")
	
	Write-host " -----------------------------------------" -ForegroundColor Green
	Write-Host (" >>> writing to file {0}" -f $fileName) -ForegroundColor Green
	$data | Export-csv $fileName -NoTypeInformation
	Write-host " -----------------------------------------" -ForegroundColor Green

	Remove-PSSession $Session
}
cls
Split-O365AuditLogs-FromO365

Enjoy your day.

 

Fabrice Romelard

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies