|
|
PowerShell IE automation and basic authentication
Hi all,
I am trying to work in a PowerShell script to automate some tasks that
requires to connect to a Web Site, I am trying this creating a com object for
IE and connecting to the site, in the case when I have form authentication I
was able to pass the user and password, login and execute the action, but now
I am dealing with a web site that use Basic authentication witch at the end
it is a dialog window where I have to provide username and password.
My code is just like this:
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($URI)
After those line I have to provide the logon credentials and the do my
stuff, I has not been able to find a way to pass credential so far.
In the case of form authentication I using the following code witch it works
(but this is not the case on basic authentication):
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($URI)
$doc = $ie.Document
$user = $doc.getElementByID("TextBoxLoginID")
$user.value = "USERNAME"
$pass = $doc.getElementByID("TextBoxPW")
$pass.value = "PASSWORD"
$Logon = $doc.getElementByID("ButtonLogin")
$Logon.click()
Does anybody know how should I handle this dialog Window and pass the
username and password? Is there anyway to pass the keystrokes in this case?
Thanks,
Zareh
|
|
0
|
|
|
|
Reply
|
Utf
|
3/30/2010 4:41:01 PM |
|
Hi Zareh,
could it be a way to overcome this issue doing the following?:
First: Determine the resulting url after GUI authentication.
then use the following code:
$cred = New Net.NetworkCredential( <username>,<password> )
$cc = New Net.CredentialCache
$url = '<resulting URL-String after GUI-Authentication>'
$authSchema = 'Basic'
$cc.Add( $url, $authSchema, $cred)
$wc = New Net.WebClient
$wc.Credentials = $cc
$result = $wc.DownloadString( $url )
the $result contains the html sourcetext and could be evaluated with the
means of regular expressions for instance.
this is a different approach than you did originally, so I'm not sure if
this is helpfull for you.
Reinhard
"Zareh" wrote:
>
> Hi all,
>
> I am trying to work in a PowerShell script to automate some tasks that
> requires to connect to a Web Site, I am trying this creating a com object for
> IE and connecting to the site, in the case when I have form authentication I
> was able to pass the user and password, login and execute the action, but now
> I am dealing with a web site that use Basic authentication witch at the end
> it is a dialog window where I have to provide username and password.
>
> My code is just like this:
>
> $ie = new-object -com "InternetExplorer.Application"
> $ie.visible = $true
> $ie.navigate($URI)
>
> After those line I have to provide the logon credentials and the do my
> stuff, I has not been able to find a way to pass credential so far.
>
> In the case of form authentication I using the following code witch it works
> (but this is not the case on basic authentication):
>
> $ie = new-object -com "InternetExplorer.Application"
> $ie.visible = $true
> $ie.navigate($URI)
> $doc = $ie.Document
> $user = $doc.getElementByID("TextBoxLoginID")
> $user.value = "USERNAME"
> $pass = $doc.getElementByID("TextBoxPW")
> $pass.value = "PASSWORD"
> $Logon = $doc.getElementByID("ButtonLogin")
> $Logon.click()
>
> Does anybody know how should I handle this dialog Window and pass the
> username and password? Is there anyway to pass the keystrokes in this case?
>
> Thanks,
>
> Zareh
>
|
|
0
|
|
|
|
Reply
|
Utf
|
3/31/2010 11:15:03 AM
|
|
|
1 Replies
725 Views
(page loaded in 0.046 seconds)
|
|
|
|
|
|
|
|
|