title: Use cookies from Post request with a Get Request with Powershell
body: <p>The issue that I am facing is getting the cookies from a POST request to use be authenticated on the following GET request. </p>
  
  <p>The issue is that despite copying the cookie to the next GET request to be authenticated I am still getting an authentication error. I am not sure what I am doing wrong.</p>
  
  <pre><code>$url = "www.example.com/post" 
  $postParams = @{user_id='username';user_password='password'}
  
  $webrequest = Invoke-WebRequest -Uri $url -SessionVariable websession -Method Post -Body $postParams
  $cookies = $websession.Cookies.GetCookies($url) 
  
   # Here, you can output all of $cookies, or you can go through them one by one. 
  
  $Nextsession=new-object microsoft.powershell.commands.webrequestsession
  
  foreach ($cookie in $cookies) { 
   # You can get cookie specifics, or just use $cookie 
   # This gets each cookie's name and value 
   Write-Host "$($cookie.name) = $($cookie.value)"
  
  
   $Nextcookie=new-object system.net.cookie
   $Nextcookie.name = $cookie.Name
   $Nextcookie.path = $cookie.Path
   $Nextcookie.value = $cookie.Value
   $Nextcookie.domain = $cookie.Domain
   $Nextcookie.expires = $cookie.Expires
  
  
   $Nextcookie.comment = $cookie.Comment
   $Nextcookie.commentUri = $cookie.CommentUri
   $Nextcookie.discard = $cookie.Discard
   $Nextcookie.expired = $cookie.Expired
  
   $Nextcookie.httpOnly = $cookie.HttpOnly
   $Nextcookie.port = $cookie.Port
   $Nextcookie.secure = $cookie.Secure
   $Nextcookie.timeStamp = Get-Date
   $Nextcookie.version = $cookie.Verison
  
  
   $Nextsession.cookies.add($cookie)
  
  }
  
  
  $url = "www.example.com/get"
  $Response = Invoke-RestMethod -Uri $url -Method Get -websession $Nextsession
  Return $Response
  </code></pre>