I am receiving an email that contains a link to a website that immediately starts a download of a file. I am able to successfully get the email and the URL, and when I paste the URL into the browser it automatically starts a download. The web page is below:
Unfortunately, the file can only be sent in an .xls format, but my end goal is to convert it to a CSV.
I know that Invoke-WebRequest is supposed to do this, and my command for that is:
Invoke-WebRequest -Uri $ExcelLink -OutFile 'C:\Temp\FileName.xls'.
I have also tried the following:
(New-Object System.Net.WebClient).DownloadFile($ExcelLink,'C:\Temp\FileName.xls')
I have tried setting the export to be both .xls and .csv, and it appears I can only get the raw HTML code, instead of the file to download. In the screenshots below the left is exporting as .csv, and the right is .xls:
I have done a decent amount of research already, and the most helpful link was this Stackoverflow post.
The link from the email does not contain the file name. I stripped out a good amount from the URL, but it looks something like this:
https://_______.com/f/a/vl6K...hRdg~~/AA...gA~/RgRnjCy...QAAAM-
I have tried adding the file name to the end of the URL and for some reason it just redirects to Google.
Does anybody know of a way to get only the file content that automatically starts downloading when entering the URL in a browser?


Invoke-WebRequestusing the link in your email and process that to extract the download link, and then you can make a second call toInvoke-WebRequestwith the actual binary file link...Invoke-WebRequestinto a variable called $Request, the value of $Request.Links.outerHTML is:<a href="#!" onclick="fileDelivery.downloadFile();">click here</a>. I tried appending#!to the end of the URL and got the same resultshttps://_______.com/...link in the email is the webpage - you need to download that first and to look deeper into how it triggers the automatic binary file download - something there knows what the link is for the target file. If the page author is trying to obfuscate it you might find it's hidden away in a http header, or another external javascript file or something else in the page source, and extracting it could require you to emulate a subset of the browser's functionality, which may end up being non-trivial...