I am trying to automate the login to a website on our intranet using Powershell and IE. So far I have the following code that works:
$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("https://somepage/jsp/module/Login.jsp/")
while($ie.ReadyState -ne 4) {start-sleep 1}
$ie.visible = $true
$doc = $ie.Document
If ($doc.nameProp -eq "Certificate Error: Navigation Blocked") {
$doc.getElementByID("overridelink").Click()
}
$loginid = $doc.getElementById("loginid")
$loginid.value= "username"
$password = $doc.getElementById("password")
$password.value = 'somepass'
$ie.navigate("javascript:doSubmit('login')",$null,$true)
So, the problem that I am facing right now is that the site closes the original window used for logging in and opens a new IE window. How can I imagine input to this new window? I know that I can use something like tasklist.exe / v to get the PID of a new window ... but I'm not sure how I would take control of this.
Also, after looking at my code, please know that I do not intend to use the built-in username and passwords. This is only in place, so I donβt need to constantly enter un / pw compilation every time I want to test a script.