mercredi 2 mars 2016

Powershell: Supress or Hide Browser during invoke-webrequest

I have a script that makes a request to download some files. The site uses certificate authentication so when I request the file (Invoke-WebRequest) it will return a form that I have to send back to the action url using Invoke-RestMethod. The code below works but it opens a new IExplorer instance to parse the form out of the response for every single call to $response.forms["form"]. This really causes a problem when I am looping over this code and requesting a lot of files. Is there a way to suppress IE? Something like $IE.visible = $false?

I should mention I tried to use the -UseBasicParsing option and tried to build the FormObject from $response.InputFields but I was not able to figure out how to create a FormObject in Powershell. I know how the object should be laid out if anyone can guide me on creating a FormObject that would help too.

Thanks!

$response = Invoke-WebRequest -uri $url -Certificate $cert
Invoke-RestMethod -uri $form_action_url -body $response.forms["form"] -method Post -OutFile $file




Aucun commentaire:

Enregistrer un commentaire