I am attempting to automate the login to website on our intranet using Powershell and IE. So far, I have the following code that works:
$ie = new-object -co
After trying a bit more...
$applist = new-object -com shell.application
$newie = $applist.windows() | where {$_.Type -eq "HTML Document" -and $_.LocationURL -match "MainFrame.jsp"}
Try this.
I found an old article that describes how to do what you're looking for, by looping through the windows of a Shell.Application
object. I have to say that while it looks possible and does seem to answer your direct question, the approach seems pretty unpleasant and fragile to me.
If you're not averse to trying a different approach, I would suggest giving Selenium Webdriver a shot. You can use the Internet Explorer driver, and the C# examples in the documentation generally translate nicely into PowerShell. You get some other nice benefits too, like drivers for other web browsers or the ability to wait for a condition instead of relying on sleep/check loops. You will also have a driver.switchTo()
function that allows you to bounce between windows or frames.