I want to download start-histricalsearch data with powershell

tarou chabi 731 Reputation points
2022-02-02T07:27:16.663+00:00

Is there a way to download the information obtained by start-histricalsearch with Powershell?
I want to download as a CSV file as if I downloaded with GUI. Or I want to automate the download process with .bat etc.

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,197 questions
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.9K Reputation points MVP Volunteer Moderator
    2022-02-02T09:11:43.68+00:00

    Hi @tarou chabi ,

    maybe this helps to get it started:

    $url = Get-HistoricalSearch -JobId xyz1234 | Select-Object FileUrl  
    Invoke-WebRequest $url -OutFile "c:\junk\test.csv"  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


1 additional answer

Sort by: Most helpful
  1. Zeg 0 Reputation points
    2025-07-11T07:17:17.1533333+00:00

    @tarou chabi
    Hi

    Let's say $mySearch = Get-Get-HistoricalSearch | Where-Object {some condition}.
    maybe, $_.ReportTitle.StartsWith('blah') or $__.NotifyAddress -contains '******@domain.com' you get the picture.
    Then you could just loop as follows:

    $mySearch |Foreach-Object {Start-Process <path to your browser app. For me it's msedge> 
    -ArgumentList $_.FileUrl }
    

    you will get $mySearch.Count save scv prompt windows as the one you get when you click on 'Download the report'. This will save you one click for each one.

    It's also better to login to your admin account before running this loop as you will need to login and reload the others before timing out.

    you could add to ArgumentList '--inprivate' for msedge or '--incognito' for chrome.

    Hope this helps.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.