2

I am attempting to get a script working that does not use invoke-webrequest. The problem I am having is that when I run the script a popup prompt occurs, the popup consists of the following message;

"Windows Security Warning To allow this website to provide information personalized for you, will you allow it to put a small file (called a cookie) on your computer?" with yes no response from user The code I am executing is the following:

$ParsedHTML = New-Object -com "HTMLFILE"
$webresponse = New-Object System.Net.WebClient
$webresponse.Headers.Add("Cookie", $CookieContainer.GetCookieHeader($url))
$result = $webresponse.DownloadString($url)
$ParsedHTML.IHTMLDocument2_write($webresponse)
$ParsedHTML.body.innerText

The main problem with this code is that the $url I am using part of the weblink checks to see if cookies are enabled and this code causes a returned value of disabled.

My question, is there a way to handle the cookie request without changing the output response from the test url site.

Note: This script will be automating a process over hundreds of remote computers and thus having an unhandled popup will just prevent the script from running.

PS-Dan
  • 21
  • 1
  • 2

1 Answers1

6

I found the answer in another SO question Using Invoke-Webrequest in PowerShell 3.0 spawns a Windows Security Warning

add the parameter -UseBasicParsing

Technet https://technet.microsoft.com/en-us/library/hh849901.aspx notes that the parameter stops the DOM processing. and has the caveat "This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system."

So, you mileage may vary.

Community
  • 1
  • 1
rob
  • 8,134
  • 8
  • 58
  • 68
  • In SharePoint when invoke-webrequest is used to get a people.aspx page for membership it can throw an error saying `init.js failed to load`. I found that -UseBasicParsing prevented the popup, but $result.allElements then does is not populated so I switched to using $result.rawcontent. Thanks Rob. – Underverse May 27 '17 at 14:31