Question

I ran this code and it allowed me to login to the website and it downloaded everything into a text file, but after the first try it as been giving me an error: "Property 'value' cannot be found on this object make sure it exists and is settable." It's been about an hour since I ran it and it worked and I didn't change the code. I cleared the cookies in internet explorer and deleted everything out of the appdata cookies folder (Only reason I could figure it was doing this was because I was already logged into the page).

EDIT: I just edited the script so that it doesn't try to login first and just grabs the page and for some reason the script it automatically logging me in now, because it's returning the information that is only view able once you login. What could cause this and how do I make it where it has to login each time?

$username = "user" 
$password = "pass" 
$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$false
$ie.navigate("website") 
while($ie.ReadyState -ne 4) {start-sleep -m 100} 
$ie.document.getElementById("username").value = "$username" 
$ie.document.getElementById("password").value = "$password" 
$ie.document.getElementById("click").click()
start-sleep 20 
$ie.Document.body | Out-File -FilePath c:\web.txt 

Here is the form html from the page I'm trying to login to:

form method="POST" action="login.php" name="loginform">
<div class="login" align="center"><p class="indent">Sign-in to your account</p></div>
  <div class="loginbot">
  <div class="email">Email Address: <br />
   <input name="username" type="text" value="" size="25" />
    <br />
    <input type="checkbox" name="remember" value="checkbox" class="small_chk1" value="ON"/>Automatically sign-in<br /></div>
  <div class="pass">Password:<br />
    <input name="password" type="password" size="25" /><br />
    <a href="login.php?ti=password">Forgot your password?</a><br /></p></div></div>
<div class="logbut"><input type="hidden" name="ti" value="do_login">
<input type="submit" value="Login ->" name="click" style="border-style: outset; border-width: 1; font-family:Verdana; color:#FFFFFF; font-size:10pt; background-image:url('images/clickbg.gif')"></div><br />
<br /></form>
Was it helpful?

Solution

I'm sure the credentials is just stored in a session/cookie somewhere.

Cookies is kept per process, so it'll be per com-object.

Is there a logout button on the page you can click? If there's is a logout, make Powershell press it after you're done downloading the content and it should clear your session, enabling you do login the next time again.

You could also try to force-clear the cookies from the process by using:

InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);

See documentation on http://support.microsoft.com/kb/195192/en

You can also clear everything in IE by invoking:

rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top