title: Invoke-WebRequest: Accept a cookie
body: <p>I'm updating the title of this, because I am sure it is to do with accepting cookies, recording it in the session variable and passing it to the next web request in the websession. Although I may be closer, I still can't do it.</p>
  
  <p>Regarding the following URI: <a href="https://support.microsoft.com/en-us/hotfix/kbhotfix" rel="nofollow noreferrer">https://support.microsoft.com/en-us/hotfix/kbhotfix</a>
  Assuming there is no cookie, one is presented with two buttons:</p>
  
  <ul>
  <li>I Accept</li>
  <li>I do not accept</li>
  </ul>
  
  <p>Using PowerShell's Invoke-WebRequest, how do I "click" I Accept?</p>
  
  <p>Using various examples from around the net, I've been trying variations of the following:</p>
  
  <pre><code>$baseUri = "https://support.microsoft.com"
  $uri = $baseURI +"/en-us/hotfix/kbhotfix"
  
  $Response = Invoke-WebRequest -Uri $uri -SessionVariable sv
  
  $Response.forms[0].Action #= /en-us/Hotfix/KbHotfix
  
  $Form = $Response.forms[0]
  $form.fields["accept"] = "Accept"
  
  $MainPage = Invoke-WebRequest -Uri ($baseUri + $Form.Action) -Method
  $form.Method -Body $form.fields -WebSession $sv
  $MainPage
  </code></pre>
  
  <p>But when I execute "$MainPage.forms[0].Fields, the resulting values are "I Do Not Accept" or "I Accept" which to me, suggests it has not "clicked I Accept.</p>
  
  <p>Do I need call the onClick event?</p>
  
  <p>Any suggestions / example would be gratefully received.</p>
  
  <p>(PowerShell V5)</p>