PS-Dan
PS-Dan

Reputation: 21

Powershell Handling cookie popup without using invoke-webrequest

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.

Upvotes: 2

Views: 6694

Answers (1)

rob
rob

Reputation: 8410

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.

Upvotes: 6

Related Questions