Results 1 to 2 of 2

Thread: Powershell Script for logging on and downloading file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Powershell Script for logging on and downloading file

    I'm trying to write a powershell script that logs onto a website via an html form using post but I can't get it to log on. All that happens is the page loads and then I get a 403 error.

    I'm not even sure if the file will download the file if it logs on as I still get a 403 error if I manually log on to the website and then run the download file code. The code for downloading the file does work though as I've used it elsewhere.

    Here's the code I'm using:

    Code:
    $ie = New-Object -com internetexplorer.application;
    $ie.visible = $true;
    $ie.navigate($url);
    while ($ie.Busy -eq $true)
    {
    Start-Sleep -Milliseconds 1000;
    }
    $ie.Document.getElementById("email").value = $username;
    $ie.Document.getElementById("password").value=$password;
    $ie.Document.getElementsByTagName("input") | 
        Where-Object { $_.Name -eq "sign_in" } | 
        ForEach-Object { $_.Click() }
    
    
    $webclient = New-Object System.Net.WebClient
    $webclient.DownloadFile($url2, $file)
    Can someone help?

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Powershell Script for logging on and downloading file

    Quote Originally Posted by garry79 View Post
    I'm trying to write a powershell script that logs onto a website via an html form using post but I can't get it to log on. All that happens is the page loads and then I get a 403 error.

    I'm not even sure if the file will download the file if it logs on as I still get a 403 error if I manually log on to the website and then run the download file code. The code for downloading the file does work though as I've used it elsewhere.

    Here's the code I'm using:

    Code:
    $ie = New-Object -com internetexplorer.application;
    $ie.visible = $true;
    $ie.navigate($url);
    while ($ie.Busy -eq $true)
    {
    Start-Sleep -Milliseconds 1000;
    }
    $ie.Document.getElementById("email").value = $username;
    $ie.Document.getElementById("password").value=$password;
    $ie.Document.getElementsByTagName("input") | 
        Where-Object { $_.Name -eq "sign_in" } | 
        ForEach-Object { $_.Click() }
    
    
    $webclient = New-Object System.Net.WebClient
    $webclient.DownloadFile($url2, $file)
    Can someone help?
    I still can't get this to work.

    I'm trying to log on via internet explorer now but can't get a reference to the form button as it just seems to treat it as an array. When I echo out the reference it brings up 2 columns - length: 1 and constructor: (is empty).

    Code:
        $passwordField = $doc.getElementById('password') 
        $passwordField.value = ($passwordfile) 
        echo $passwordField.parentNode.nextsibling.nextsibling.childnodes[0]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width