Powershell downloads the login webpage html instead of a file

%3CLINGO-SUB%20id%3D%22lingo-sub-2780169%22%20slang%3D%22en-US%22%3EPowershell%20downloads%20the%20login%20webpage%20html%20instead%20of%20a%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2780169%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20website.com%20where%20I%20login%20via%20a%20form%20and%20it%20has%20a%20second%20step%20authentication%20too.%20After%20I%20fully%20login%2C%20a%20session%20starts%20and%20I%20can%20type%20a%20specific%20url%20in%20the%20address%20bar%20of%20IE%2FEdge%20and%20it%20will%20trigger%20a%20download%20of%20an%20xlsx%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20get%20these%20files%20every%2030%20min%20and%20I%20was%20checking%20Powershell%20as%20other%20options%20are%20limited.%20However%2C%20using%20Invoke-WebRequest%20results%20in%20downloading%20the%20login%20webpage%20html%20instead%20of%20the%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20idea%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20do%20you%20know%20any%20other%20method%20to%20get%20these%20files%20regularly%20so%20that%20the%20session%20renews%3F%20It%20is%20impossible%20to%20automate%20the%20login%20as%20it%20requires%20a%20mobile%20phone.%20An%20API%20is%20paid%20so%20again%20it's%20not%20an%20option.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20tried%20a%20Data%20Connection%20in%20Excel%20but%20it%20does%20download%20the%20same%20html.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2780169%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Logic%20Apps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Flow%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Hello

 

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.

 

Thanks!

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/