powershell Invoke-WebRequest WebSession not working powershell Invoke-WebRequest WebSession not working powershell powershell

powershell Invoke-WebRequest WebSession not working


There is an event target field that also needs to be set, also the POST needs a different URL, i tested the solution below and it works:

$login = Invoke-WebRequest -Uri 'http://www.sqlpass.org/UserLogin.aspx' -SessionVariable sqlpass$form = $login.Forms[0]$form.Fields["__EVENTTARGET"] = "UserLogin"$form.Fields["txtUsername_14615"] = 'myuser'$form.Fields["txtPassword_14615"] = 'mypass'Invoke-WebRequest -Uri 'http://www.sqlpass.org/UserLogin.aspx?returnurl=%2fdefault.aspx' -WebSession $sqlpass -Method POST -Body $form.Fields

Note: Just as a side note, you can use Web Debugging proxies like Fiddler to debug issues like this, which is exactly what i did.