'Login to website with powershell without IE COM method
Looking for solution how to test website login with powershell without IE COM method. There is lot of examples how to do it with IE COM method: -ComObject 'internetExplorer.Application, but unfortunately this is not working for me as site is not working with IE at all.
Solution 1:[1]
Google chrome has a nice feature in its developer tools, on the network tab.
Clear the network log, filter so that it shows "All" requests/responses.
Log into the site and then click the red button or hit "ctrl + e" to stop the log from increasing.
Go through each request until you see the login request (These can sometimes be hard to spot.)
Once you have found the request right click on the name of the request, you can then select "Copy -> Copy As PowerShell".
Paste this into ISE etc.
I would personally then remove all of the $Session lines from above the request and change -WebSession $session to -SessionVariable $session and subsequently call -WebSession $session in each web request there after. (Only use -Sessionvariable once as this is the what instantiates the session). The reason I do this is so that the login creates its own session data rather than using any possible data from the browser.
Last of all you will want to clear any unwanted headers out of the webrequest.
Depending on the login mechanism the request may need tweaking to allow it to be done through automation, I have only had a couple of circumstances where this has been the case and multiple requests have been required due to AJAX or other elements on the page.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CraftyB |
