title: How to sign into a website using the new param -form in pwsh
body: <p>PowerShell 6.2.1 doesn't return a Forms property using Invoke-WebRequest. The way I used to do it in Powershell 5:</p>
  <pre><code>$r = Invoke-WebRequest -Uri 'somewebsite.com' -SessionVariable f
  $f
  $form = $r.Forms[0]
  
  $form.Fields[&quot;userName&quot;] = &quot;username&quot;
  $form.Fields[&quot;brokerPassword&quot;] = &quot;password&quot;
  
  $login = Invoke-WebRequest -Uri 'somewebsite.com' -WebSession $f -Method 
  POST -Body $form.Fields
  </code></pre>
  <hr />
  <p>I see in the Microsoft documentation that there is now a <code>-Form</code> parameter you can use, but I've been hacking at it for a few hours now with very little success.</p>
  <p><a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6</a></p>
  <p>They provided two possible solutions.</p>
  <p>Example 1</p>
  <pre><code>$Uri = 'https://api.contoso.com/v2/profile'
  $Form = @{
  firstName  = 'John'
  lastName   = 'Doe'
  email      = 'john.doe@contoso.com'
  avatar     = Get-Item -Path 'c:\Pictures\jdoe.png'
  birthday   = '1980-10-15'
  hobbies    = 'Hiking','Fishing','Jogging'
  }
  $Result = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form
  </code></pre>
  <hr />
  <p>Example 2</p>
  <pre><code>$Body = @{
  User = 'jdoe'
  password = 'P@S$w0rd!'
  }
  $LoginResponse = Invoke-WebRequest 'http://www.contoso.com/login/' - 
  SessionVariable 'Session' -Body $Body -Method 'POST'
  
  $Session
  
  $ProfileResponse = Invoke-WebRequest 'http://www.contoso.com/profile/' - 
  WebSession $Session
  
  $ProfileResponse
  </code></pre>
  <p>I have tried both and my current code block is a combination of the two and it gets me at least a good failure.</p>
  <pre><code>$username = 'useremail@gmail.com'
  $password = 'p@ssw0rd'
  $form = @{    
  LoginForm_password = $password
  LoginForm_username = $username
  }
  $result = Invoke-WebRequest 'https://www.podbean.com/login' - 
  SessionVariable foo -Form $form -Method POST
  $foo
  
  $result | Get-Member | Format-table
  </code></pre>
  <p>This is the error I am now getting.</p>
  <p>Invoke-WebRequest :</p>
  <p>403 Forbidden</p>
  <p>Forbidden
  You don't have permission to access /login
  on this server.</p>
  <blockquote>
  <p>At line:7 char:11</p>
  <ul>
  <li>$result = Invoke-WebRequest 'https://www.podbean.com/login' -SessionV  ...</li>
  <li>
  <pre><code>      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  </code></pre>
  </li>
  <li>CategoryInfo          : InvalidOperation: (Method: POST,  Reque\u2026tent-Length: 357 }:HttpRequestMessage) [Invoke-WebRequest],
  HttpResponseException</li>
  <li>FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand</li>
  </ul>
  </blockquote>
  <p>This is actually the best response I've got.</p>