I’m new to learning powershell and picking up the basics just now. I have a an application that runs internally through IE, it is apache based and it coded in HTML. The url is http://localhost/form on this page it has a username field and password field and I want to automate the login then eventually go to a particular page with some menus that control a DLL file and send a value to that DLL.
To start with I just want to get the login automated then work on the other aspects. I’ve viewed the source code from the web page to determine the fields for the username and password fields and how I can pass the credentials to these fields and login. Would anyone be able to point me in the right direction as this is all new to me. I’ve never had to much scripting or work with syntax before.
Hello yes I’ve already been using the invoke-webrequest cmdlet and been reading about it. I’ve managed to write some lines of code but not entirely successful so far. What I am trying to work out is what are the HTML elements within the source code on the webpage that control the input fields for the username and password controls and how I can get powershell to interact with the these.
I don’t have experiences with that but as far as I understood usually you don’t interact with the controls at all. Take a look at the example #2 of the help. It shows how to provide credentials for a web page.
As Olaf stated, this is a bit advanced. The code below was logging into a website to get to a table and parsing it, which was a total pain. To this, I was hitting F12 in the browser and watching the network traffic and trying to emulate it with Powershell and HTML Document Object Model (DOM):
$Uri = 'https://someevent.com'
$Username = 'user'
$Password = 'password'
#Login page
$evtLogon = Invoke-WebRequest -Uri ('{0}/exhibitor/login.do'-f $Uri) -SessionVariable session
#fill the form body with the username\pw
$formBody = @{username=$Username;password=$Password}
$params = @{
Method = 'POST'
Uri = ('{0}/exhibitor/processLogin.do'-f $Uri)
Body = $formBody
WebSession = $session
}
#attempt login
$evtLoggedOn = Invoke-WebRequest @params
$params.Remove('Method')
$params.Remove('Body')
$params.Set_Item('Uri', ('{0}/exhibitor/leads.do'-f $Uri))
#go to the page after authentication, find all buttons and click on the 3rd button
$leads = ((Invoke-WebRequest @params).ParsedHTML.getElementsByTagName("button")[2]).Click()
Took a while with trial and error trying to get it to work, but it was working albeit slow. The best way to get data is an API. If they do not have an API, then you are stuck doing something like this.