0

I want to automate a thing in IE using power shell , I have the following snippet:

$ie = new-object -com "InternetExplorer.Application";
$ie.navigate('http://urlWithAuthentication.com');

this url has http authentication, so the browser prompts for the user and password, the previous script works fine, but I would like to not interactively set the user and password.

for example:

This does not exist, looking for something similar

$ie.navigate('http://urlWithAuthentication.com','user','password');

there's nothing about authentication in the method documentation http://msdn.microsoft.com/en-us/library/aa752093%28v=vs.85%29.aspx

I've found questions similar but they were targeting when there's a login page (i.e. user/pass form), in this case I'm targeting to handle the browser's builtin user/pass promt.

Leo
  • 1,829
  • 4
  • 27
  • 51
  • See here for a potential solution: http://stackoverflow.com/questions/12282842/how-to-login-to-website-with-basic-authentication-using-powershell – David Brabant Apr 22 '14 at 06:41
  • @DavidBrabant that's not the solution I'm looking for, cause System.Net.WebClient just donwloads the resource, I would need to parse the html and manipulate dom and then build another request to interact with the page. all those things are encapsulated in InternetExplorer.Application – Leo Apr 22 '14 at 20:02

2 Answers2

2

I don't believe there is a function within the COM Object because i've also looked for this in the past, my own automation scripts use Wscript.Shell to send the Username, press tab, sent the password and then send the enter key.

# setup ie object and open website
$ie = new-object -com "InternetExplorer.Application";
$ie.navigate('http://urlWithAuthentication.com');
$passwordSent = 0
# wait for website to load
While ($ie.ReadyState -ne 4)
{
    Sleep -Milliseconds 500
        if ($ie.ReadyState -eq 1) {
             if ($passwordSent -eq 0) {
             $comShell = New-Object -com "Wscript.Shell" 
             $comShell.sendkeys($password)
             $comShell.sendkeys("{ENTER}")
             $passwordSent = 1;
        }
}
Bluecakes
  • 2,069
  • 17
  • 23
  • thanks, I also did not find any other approach, you almost wrote the right script, except that the part of sending the keys goes inside the while loop, the user/password prompt happens when ReadyState is "Loaded" – Leo Jun 04 '14 at 17:58
-1

This is what worked for me. It works, however I receive an error because of the password I used. I think I need to make a new function to pass the password to the login mask,

# setup ie object and open website
$ie = new-object -com "InternetExplorer.Application";
$ie.navigate('http://YOURWEBSITE');
$passwordSent = 0
# wait for website to load
While ($ie.ReadyState -ne 4)
{
 Sleep -Milliseconds 500
  $comShell = New-Object -com "Wscript.Shell" 
  $comShell.sendkeys($username)
  $comShell.sendkeys("{TAB}")
  $comShell.sendkeys($password)
  $comShell.sendkeys("{ENTER}")
  $passwordSent = 1;
}
ray
  • 5,454
  • 1
  • 18
  • 40