Powershell downloads the login webpage html instead of a file

Copper Contributor



I have a website.com where I login via a form and it has a second step authentication too. After I fully login, a session starts and I can type a specific url in the address bar of IE/Edge and it will trigger a download of an xlsx file.


I want to get these files every 30 min and I was checking Powershell as other options are limited. However, using Invoke-WebRequest results in downloading the login webpage html instead of the file.


Any idea?


Also, do you know any other method to get these files regularly so that the session renews? It is impossible to automate the login as it requires a mobile phone. An API is paid so again it's not an option.


Also, tried a Data Connection in Excel but it does download the same html.



1 Reply
Depending on how that web site handles authentication, you may need to figure that out first, but a tip is to press f12 in your browser, do whatever you want to do, then right-click the relevant HTTP commands to "copy as powershell"

e.g. https://www.powershellbros.com/powershell-tip-of-the-week-create-invoke-webrequest-from-chrome/