How can I programatically download the output of Get-HistoricalSearch?

I have to use Powershell to perform some message tracing. This involves using Start-HistoricalSearch to begin a search, followed by Get-HistoricalSearch to get the results once it's done. Get-HistoricalSearch returns data along these lines:

PS C:\Users\dscally> Get-HistoricalSearch -JobId "e4e8cecd-e943-4d61-b588-6a0a3c8d3cba" | select * RunspaceId : 9b3d4d8f-c257-477e-b4e9-8379c2bf788f JobId : e4e8cecd-e943-4d61-b588-6a0a3c8d3cba Identity : e4e8cecd-e943-4d61-b588-6a0a3c8d3cba SubmitDate : 09/06/2020 13:25:40 ReportTitle : First 50 People -90 Days Received Status : Done Rows : 171069 FileRows : 50000 ErrorCode : ErrorDescription : FileUrl : < report URL here> ReportStatusDescription : Complete – Ready for download ReportType : MessageTrace NotifyAddress : {< my email address here >} StartDate : 11/03/2020 14:25:40 EndDate : 09/06/2020 14:25:40 DeliveryStatus : All SenderAddress : {} RecipientAddress : {<addresses go here>...} OriginalClientIP : MessageID : {} DLPPolicy : {} TransportRule : {} Locale : en-GB Direction : All CompletionDate : 09/06/2020 13:47:10 EstimatedCompletionTime : JobProgress : EncryptionType : EncryptionTemplate : IsSaved : False NumOfBlocks : 0 CompressFile : False NetworkMessageID : {} Url : 

I need to ideally programatically fetch the report linked to by the FileURL property. Unfortunately it's behind a Microsoft SSO authentication page, and I'm struggling to do it other than through the GUI. Is there a way to pass the authentication it needs through Invoke-WebRequest or some other cmdlet so that I can download the reports with a script.

The context is, there's like several hundred of these and that's more manual clicking than I really want to do.

2 Answers

Try this to download the log with Edge:

$logg = Get-HistoricalSearch -JobId xxxxxx... | select FileUrl & 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' $logg.FileUrl 

Could you see the value of the FileUrl parameter if you download the report via EAC(mail flow -> message trace -> View pending or completed traces -> Download this report) or export the report to a CSV via the command "Get-HistoricalSearch -JobId "<Search JobId>" | select * | Export-Csv <.CSV File Path>\Report.csv"? enter image description here

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like