[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Powershell login to website

Posted on 2014-08-30
27
Medium Priority
?
1,279 Views
Last Modified: 2014-10-05
What I find different about this page is that the html does not have a  value="" field to store user name and password for login so how can it be done.

cls
#if (!(Get-Variable ie -Scope global -ea SilentlyContinue)) { $global:ie = New-Object -comobject InternetExplorer.Application }
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true



$wc = New-Object System.Net.WebClient
$login = "User"
$password = "password#"

$url = "https://ultidev/secure/Dashboard.jspa"

[string] $content = $wc.DownloadString($URL)

$ie.Navigate2($url)
  while ($ie.busy)                               { Start-Sleep -m 100 }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

Start-Sleep -s 5

$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-username' } | % { $_.value = $login    }
$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-password' } | % { $_.value = $password }
$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'login'        } | % { $_.Click() }

Open in new window




<div class="view g-login"><div id="content"><form name="loginform" class="aui gdt" id="loginform" action="#" method="post"><div class="field-group"><label id="usernamelabel" accesskey="u" for="login-form-username"><u>U</u>sername</label><input name="os_username" class="text medium-field" id="login-form-username" type="text"></div><div class="field-group password"><label id="passwordlabel" accesskey="p" for="login-form-password"><u>P</u>assword</label><input name="os_password" class="text medium-field" id="login-form-password" type="password"></div><fieldset class="group"><div class="checkbox" id="rememberme"><input name="os_cookie" class="checkbox" id="login-form-remember-me" type="checkbox" value="true"><label id="remembermelabel" accesskey="r" for="login-form-remember-me"><u>R</u>emember my login on this computer</label></div></fieldset><div class="field-group hidden" id="captcha"><label id="captchalabel" accesskey="c" for="login-form-captcha">Please enter the word as shown below</label><input name="os_captcha" class="text medium-field captcha-response" id="login-form-captcha" type="text"><div class="captcha-container"><img width="200" height="100" class="captcha-image" id="captchaimg" alt="" src=""><a tabindex="-1" title="Refresh the image" class="captcha-trigger" id="os-captcha-icon" href="#login-form-os-captcha"><span class="aui-icon captcha-reload icon-reload">Refresh the image</span></a></div></div><div class="field-group" id="publicmodeooff"><div id="publicmodeoffmsg">Not a member? To request an account, please contact your <a id="contact-admin" href="https://ultidev/secure/ContactAdministrators!default.jspa" target="_parent">JIRA administrators</a>.</div></div><div class="buttons-container"><div class="buttons"><input name="login" class="button" id="login" type="submit" value="Log In"><a class="button aui-button-cancel cancel" id="forgotpassword" href="https://ultidev/secure/ForgotLoginDetails.jspa" target="_parent">Can't access your account?</a></div></div></form></div></div>

Open in new window

0
Comment
Question by:Leo Torres
  • 13
  • 7
  • 7
27 Comments
 
LVL 1

Assisted Solution

by:rwniceing
rwniceing earned 400 total points
ID: 40294231
You  can  try to add this

$ie.Document.getElementById("login-form-username").value= "$login"
$ie.Document.getElementById("login-form-password").value = "$password"
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40294240
Add or Replace what I have with what you suggested?
0
 
LVL 1

Expert Comment

by:rwniceing
ID: 40294243
you can set the default value for input tage 's  username and password  inside  the form so that you can submit the form with the username and password you set at

$login = "User"
$password = "password#"

<form name="loginform" class="aui gdt" id="loginform" action="#" method="post">
<div class="field-group"><label id="usernamelabel" accesskey="u" for="login-form-username"><u>U</u>sername</label>
<input name="os_username" class="text medium-field" id="login-form-username" type="text"></div>
<div class="field-group password"><label id="passwordlabel" accesskey="p" for="login-form-password"><u>P</u>assword</label>
<input name="os_password" class="text medium-field" id="login-form-password" type="password"></div>
.....................

</form>

Open in new window

0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
LVL 1

Expert Comment

by:rwniceing
ID: 40294292
it seems your post code is already done your need.

Actually did you try your code, working or not ? OR could you write more about your question
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40294296
Code does not work now it produces error.


The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:25 char:1
+ $ie.Document.getElementById("login-form-username").value= "$login"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:26 char:1
+ $ie.Document.getElementById("login-form-password").value = "$password"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Open in new window

0
 
LVL 1

Expert Comment

by:rwniceing
ID: 40294300
Could you post the whole code ? where you put those two lines in  the code ?


This link is good reference to your question at EE link
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28379350.html
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40295140
OK here is the code but I dont see the Username tag any where I wonder if its encrypted or something.

Here is the code thru DOM Explorer

COde
I cant see this in HTML Wonder if this is a deal breaker.
Sample.html
0
 
LVL 1

Expert Comment

by:rwniceing
ID: 40295145
$login = "User"
$password = "password#"

$ie.Document.getElementById("login-form-username").value= "$login"
$ie.Document.getElementById("login-form-password").value = "$password"

the userlogin name is at input tag with id , login-form-username , so you
just put your username at  $login

where those two code you put ,please read the reference link
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40296313
Produced Error

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:17 char:1
+ $ie.Document.getElementById("login-form-username").value= "$login"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:18 char:1
+ $ie.Document.getElementById("login-form-password").value = "$password"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Open in new window


Actual code
$login = "ID"
$password = "passwd"

$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true

$ie.Navigate2($url)
  while ($ie.busy)                               { Start-Sleep -m 100 }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }


$ie.Document.getElementById("login-form-username").value= "$login"
$ie.Document.getElementById("login-form-password").value = "$password"

Open in new window

0
 
LVL 1

Expert Comment

by:rwniceing
ID: 40296376
What is url full path ?
Could you try to Navigate instead of  Navigate2

On VBA, value should be Value , but  probably on here , it is okay
for lower case of 'v" ?
0
 
LVL 1

Expert Comment

by:rwniceing
ID: 40296392
while($ie.ReadyState -ne 4) is not  while ($ie.Document.ReadyState -ne "Complete") that   will cause issue since the document is not ready so there is no object with value Please check it out
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40296895
rwniceing,

.value or .Value does not matter. Nor does .Navigate or .Navigate2. The latter is able to resolve more than an URL, e.g. a file with registered type, that is all.

In regard of the ready state, since IE isn't busy anymore, the document is available - it might be not ready yet (but should). That will not cause an issue.


Leo,

You should first see if typing
$ie.Document.getElementById("login-form-username")
$ie.Document.getElementById("content").getElementById("login-form-username")

Open in new window

shows any object.
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40297566
Not at work now will try to test this tomorrow
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40319040
Guys sorry for the delay. I have been sick and out the past week. I will be back on the next for days

Code opens page put does not enter data into fields

cls
#if (!(Get-Variable ie -Scope global -ea SilentlyContinue)) { $global:ie = New-Object -comobject InternetExplorer.Application }
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true

$wc = New-Object System.Net.WebClient
$login = "User"
$password = "pass"

$url = "https://ultidev/secure/Dashboard.jspa"

[string] $content = $wc.DownloadString($URL)

$ie.Navigate2($url)
  while ($ie.busy)                               { Start-Sleep -m 100 }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

Start-Sleep -s 5

$ie.Document.getElementById("login-form-username")
$ie.Document.getElementById("content").getElementById("login-form-username")

#$ie.Document.getElementById("content").getElementById("login-form-username") | ? { $_.Id   -eq 'login-form-username' } | % { $_.value = $login }
#$ie.Document.getElementById("login-form-username").value= "$login"
#$ie.Document.getElementById("login-form-password").value = "$password" 
#$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-username' } | % { $_.value = $login    }
#$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-password' } | % { $_.value = $password }
#$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'login'        } | % { $_.Click() }

Write-Host $content

Open in new window

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40319150
Lines 21 and 22 should have some output - do they? You need not to execute the lines following those for now.
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40320718
Here is the out put

Image
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40320725
The web page comes up but the User name is not filled in
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40320758
Ok, try if
 ($ie.Document.getElementById("login-form-username") | select -first 1).value = 'x'
sets something in the username field. We do not have to do that with the HTML fragment you posted in the question, but maybe you have to on your real page.

If that works, use (I've removed some irrelevant code you might have to readd for your purpose):
cls
#if (!(Get-Variable ie -Scope global -ea SilentlyContinue)) { $global:ie = New-Object -comobject InternetExplorer.Application }
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true

$login = "User"
$password = "pass"

$url = "https://ultidev/secure/Dashboard.jspa"

$ie.Navigate2($url)
while ($ie.busy)                               { Start-Sleep -m 100 }
while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

Start-Sleep -s 5

($ie.Document.getElementById("login-form-username") | select -first 1).value = $login
($ie.Document.getElementById("login-form-password") | select -first 1).value = $password
$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'login'        } | % { $_.Click() }

Open in new window

0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40321413
Code produced this error.

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:19 char:1
+ ($ie.Document.getElementById("login-form-username") | select -first 1).value = $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:20 char:1
+ ($ie.Document.getElementById("login-form-password") | select -first 1).value = $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Open in new window


I have also attached page source here.
jiraSite.txt
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40321591
No, that is not the correct site code. It is the dashboard, and you need to click the "Log In" link to go to a login page.
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40322423
This is the site code here it is again

Here is what the page looks like
page
Any reason why you think this is not the code?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40322797
This is what I see:jiraSite.png
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40322832
Yes your right. I get the same thing.

I went to link then had it show source. copied pasted it did it twice to make sure. same thing.

if I do a get-content I get the same file .

How ever if I open the page and hit F12 and copy  from the DOM Explorer I do see the login fields.

I have attached new html file here from DOM Explorer. Hope this works?
jiraSite-DOMExplorer.txt
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40323096
Nope, seems to be active code instead of static fields. And that is probably the reason the PS code does not work.
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40331944
So your saying it cant be done?
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 1600 total points
ID: 40332145
No, not saying that, but probably you are the only one able to check and solve. You are seeing different stuff than we do.

You'll have to dump part of the code PS sees at that moment you see the login, and then try to find the object with getElementByID or getElementsByXXX (tagname, name, type, ...). Play with it, don't be focussed on the static code for now. As soon as you are able to fill in login data with an assignment, you can put that into the code. That is the way I work with such stuff.
0
 
LVL 8

Author Closing Comment

by:Leo Torres
ID: 40362698
Sorry about the delay gave you guys. I really want to do this I will repost. Just have to many things going on.
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question