title: Powershell websession
body: <p>My question is, I'm logging into a website using invoke web-request.  I'm able to successfully login to the website.  My problem is that, when I go to a url, it thinks I'm not logged in.  I'm using the same session variable to login and to go to the specific page.</p>
  
  <p>This is the screenshot showing I'm logged in, but I can't go the part of the website to upload some files.</p>
  
  <p><a href="https://drive.google.com/open?id=18tr4aBxTkroQKl1E1SOAEyeJ70LH2LC0" rel="nofollow noreferrer">https://drive.google.com/open?id=18tr4aBxTkroQKl1E1SOAEyeJ70LH2LC0</a></p>
  
  <pre><code>$Global:organization = Read-Host "`tEnter the organization"
  $username = Read-Host "`tEnter the username"
  $password = Read-Host "`tEnter the password"
  
  $form.fields["organization"] = $organization
  $form.fields["Username"] = $username
  $form.fields["Password"] = $password
  
  $Global:loginResponse = Invoke-WebRequest -uri ("https://dealer.md-bmc.rpdss.com/" + $form.Action) -WebSession $login -Method post -Body $form.Fields
  
  if ($loginResponse.ParsedHtml.title -eq "RAPID Dealer Reporting Site") {
      Write-Host "`tLog in failed, please try again! `n" -ForegroundColor Red
  }
  
  else {
  $info = $loginResponse.AllElements | where {$_.tagName -contains "span"}
  $account = ($info.innerhtml | Select-Object -First 3).ToUpper()
  Write-Host "`tLogged in as" $account "`n" -ForegroundColor Green
  $upload = $loginResponse.AllElements.InnerHtml | Where-Object {$_ -match 'url="(administration/uploadprofileselector.aspx\?.*?)"'} |ForEach-Object {$matches[1]} | Select-Object -First 1
  
  $uid = ($upload -replace '\D').Substring(0,4)
  $oid = ($upload -replace '\D').Substring(4,6)
  
  #this is where it "forgets" that it's already logged in.
  
  $fileUploadurl = "https://dealer.md-bmc.rpdss.com/bwident/pawnshop/administration/uploadprofileselector.aspx?l=English&amp;uid=$uid&amp;oid=$oid"
  $fileUploadPage = Invoke-WebRequest -Uri $fileUploadurl -WebSession $login
  
  #this should be showing me a selection menu, but it's asking me to login again.  Please see screenshot.
  $fileUploadPage.ParsedHtml.body.innerText
  }
  </code></pre>