Author Posts

August 12, 2014 at 8:40 am

My goal for this script is to pull the IDs that are on one of the lookup sites that I have. This script allows me to log in and run the users names that are stored in a csv through the site.

cls
$username = "Test"
$password = 'User'
write-host "Begin User Search `n"
write-host "Launching IE`n"
# Creates a new instance of IE
$ie = New-Object -com InternetExplorer.Application
$html = $ie.document
# Makes IE Visible
$ie.visible=$true;
# Gives IE Time to load
start-sleep -milliseconds 2000
write-host "`nNavigating to PersonLookup"
# Goes to PersonLookup Site
$ie.navigate("https://www.test.com/default.aspx");
write-host "`nLoging in"
while($ie.ReadyState -ne 4) {start-sleep -m 100}
# Puts Credentials in the login form
$ie.document.getElementById('j_username').value= "$username"
$ie.document.getElementById('j_password').value = "$password"
# $ie.document.getElementById('_idp_authn_lc_key').click();
start-sleep 3

# Starts the user lookup process
# Gets the Users
cls
Import-Csv -Path 'C:\users\Test\documents\check\Names.csv' | ForEach-Object {
$LastName=$_.GivenName
$FirstName=$_.SurName
# Puts Last Name Information in the form
$ie.document.getElementById('dnn_ctr755_View_ctrlSearchCriteria_txtLastName').value= $LastName
# Puts First Name Information in the form
$ie.document.getElementById('dnn_ctr755_View_ctrlSearchCriteria_txtFirstName').value= $FirstName
# Submits the Information
$ie.document.getElementById('dnn_ctr755_View_ctrlSearchCriteria_ctrlCOBSearch').click();
# Searches the Objects that were returned
$ie.document.getElementById('dnn_ctr755_View_ctrlPeopleSearchResult_gv_ctl02_ImageButton1').click();
# Gets the PVI Information
$PVI = $ie.document.getElementById("dnn_ctr755_View_ctl00_lbPVI").innerHTML
$PVI | Out-File -FilePath 'C:\users\Test\documents\check\Lookup.txt' -append
start-sleep 3
}

This gets the first persons PVI ( ID ) and then it does not seem to work past $ie.document.getElementById('dnn_ctr755_View_ctrlSearchCriteria_ctrlCOBSearch').click(); (inside the foreach loop).

I also included the script as an attachment

August 12, 2014 at 11:04 am

There's really nothing we can do to help with this, without having access to the website itself. Webpage scraping, particularly through IE automation, is a very error-prone and fragile process. If this is your only option, you might have better luck using Invoke-Webrequest (in conjunction with its -SessionVariable and -WebSession parameters). There are examples in the Invoke-WebRequest help file for how to use these options to log on to Facebook, for example.

However, an even better solution, assuming it's an option, would be for this website to expose the data via a REST API in addition to (or instead of) the webpage you're currently using.

August 12, 2014 at 11:45 am

The website is a company one and i only have access to retrieve information, not to modify. As for the Invoke-Webrequest, Powershell v1 is installed and i cant install the anything higher. Thanks for the ideas though.

August 12, 2014 at 12:28 pm

I wish you luck; that's a pretty crappy set of conditions to have to work through.

The only thing that jumps out at me right now is that you're performing actions immediately after calls to click() on buttons, without allowing time for any navigation to complete. Try adding some loops that wait for the $ie.Busy property to be $false:

$ie.document.getElementById('dnn_ctr755_View_ctrlSearchCriteria_ctrlCOBSearch').click();

while ($ie.Busy)
{
    Start-Sleep -Milliseconds 100
}

$ie.document.getElementById('dnn_ctr755_View_ctrlPeopleSearchResult_gv_ctl02_ImageButton1').click();

while ($ie.Busy)
{
    Start-Sleep -Milliseconds 100
}

$PVI = $ie.document.getElementById("dnn_ctr755_View_ctl00_lbPVI").innerHTML
$PVI | Out-File -FilePath 'C:\users\Test\documents\check\Lookup.txt' -append

If that doesn't help, the problems may be related to the specific site, which we can't see.

August 13, 2014 at 6:44 am

Thanks, That made it put out what i wanted.