Get-ComplianceSearch / Get-ComplianceSearchAction download the search and export statistics file via powershell
I am trying to download the Search and Export statistics from office 365 compliance search.
I am able to export the results using below query. But I need the statistics. How can I do that?
Get-ComplianceSearchAction -Identity "Sam_PS_Search2_Preview" | Select Results | Export-Csv c:\tempz\results.csv
2 Answers
I know this is old but I just needed the same solution as the op. Here's what I did.
$Results = (Get-ComplianceSearchAction 'searchName_Preview' -Details).Results -replace '{', "Location,Sender,Subject,Type,Size,ReceivedTime,DataLink`r`n" -replace '}' -replace 'Location: ' -replace '; Sender: ', ',' -replace '; Subject: ', ',' -replace '; Type: ', ',' -replace '; Size: ', ',' -replace '; Received Time: ', ',' -replace '; Data Link: ', ',' -replace ",`r`n", "`r`n" | Out-File $Home\Desktop\Results.csv
After this I had to (in Excel) use the Text to Columns feature on Column A to separate using Comma as the delimiter. I messed with it for a while to make my pseudo CSV auto-recognize in Excel but didn't get it opted to use Text to Columns rather than waste anymore seconds off my life.
👉 For more insights, check out this resource.
I don't know who they were trying to please when they designed this suite of cmdlets. The Results field is horrendous. Should be JSON or CSV ready. I can't think of anyone who would be pleased with the current format, which is one of kind.
If by "statistics" you mean each location in the results, then exporting to CSV isn't going to work because the data isn't in that format. You can, however, use Out-File instead:
👉 Discover more in this in-depth guide.
$results = Get-ComplianceSearchAction -Identity "Sam_PS_Search2_Preview" | Select Results
$results.Results | Out-File c:\tempz\results.txt
This will get you a file with all of the results, similar to this:
{Location: [email protected]; Sender: William; Subject: IM/henlo hammy birb; Type: IM; Size: 17880; Received Time: 8/27/2018 1:40:24 PM; Data Link: data/All/FLDRe9310163-848f-472e-9875-298548b21d6e/BATCH0000/MSG7d1a50f4-7c52-4f63-9f36-88555d97f123.eml, Location: [email protected]; Sender: Douglas; Subject: IM/henlo hammy birb; Type: IM; Size: 18067; Received Time: 8/27/2018 1:34:30 PM; Data Link: data/All/FLDRe9310163-848f-472e-9875-298548b21d6e/BATCH0000/MSG5a03c111-9b93-4b8f-838c-a72514d4af64.eml, Location: [email protected]; Sender: CHRISTOPHER; Subject: IM/Poo Limit Exceeded; Type: IM; Size: 17873; Received Time: 8/31/2018 12:11:00 AM; Data Link: data/All/FLDRe9310163-848f-472e-9875-298548b21d6e/BATCH0000/MSG6eba5094-5ee6-4100-b952-d94e96539530.eml,}