script to loop though a set of web pages
If I have a text file that has the URL's of some webpages, how can I write a PowerShell script to loop through them, and refresh the display when it displays one in a web browser?          
September 17th, 2011 1:18am

Try this: 

$ie = new-object -com InternetExplorer.Application 
$ie.Visible = $true

get-content "C:\listofurl.txt" | % {

$ie.navigate($_) 

do {sleep 1} until (-not ($ie.Busy)) 

Sleep 10 # pause

}


Free Windows Admin Tool Kit Click here and download it now
September 17th, 2011 2:03am

Try this: 

$ie = new-object -com InternetExplorer.Application 
$ie.Visible = $true

get-content "C:\listofurl.txt" | % {

$ie.navigate($_) 

do {sleep 1} until (-not ($ie.Busy)) 

Sleep 10 # pause

}


September 17th, 2011 2:03am

Try this: 

$ie = new-object -com InternetExplorer.Application 
$ie.Visible = $true

get-content "C:\listofurl.txt" | % {

$ie.navigate($_) 

do {sleep 1} until (-not ($ie.Busy)) 

Sleep 10 # pause

}


Free Windows Admin Tool Kit Click here and download it now
September 17th, 2011 2:03am

Thanks!   I found this documentation so far http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx   If you know of other resources for InternetExplorer.Application examples, please post them.  
September 17th, 2011 2:18pm

What if I want to infinite loop through these pages until I manually kill the process or CTRL+C?

 

I tried adding an

 

 

do {

...

} until ($a -eq $b)

 

to set some arbitrary variables which would never equal each other but that didn't work.  I'd like to keep cycling through the pages in that list essentially.

 

EDIT: 

I quickly found out how to do an infinite loop.  Simply append 

 

  for (;;) {  ... scriptblock } 

To any scriptblock to make it loop infinitely.  In my shop we used this structure to build a list of SCOM web reports and general environmental health statistics which are cycled through on a number of monitors every few minutes.  Works great!


  • Edited by Stephen Owen Thursday, October 13, 2011 4:52 PM Adding Content
Free Windows Admin Tool Kit Click here and download it now
October 13th, 2011 7:39pm

What if I want to infinite loop through these pages until I manually kill the process or CTRL+C?

 

I tried adding an

 

 

do {

...

} until ($a -eq $b)

 

to set some arbitrary variables which would never equal each other but that didn't work.  I'd like to keep cycling through the pages in that list essentially.

 

EDIT: 

I quickly found out how to do an infinite loop.  Simply append 

 

  for (;;) {  ... scriptblock } 

To any scriptblock to make it loop infinitely.  In my shop we used this structure to build a list of SCOM web reports and general environmental health statistics which are cycled through on a number of monitors every few minutes.  Works great!


  • Edited by Stephen Owen Thursday, October 13, 2011 4:52 PM Adding Content
October 13th, 2011 7:39pm

What if I want to infinite loop through these pages until I manually kill the process or CTRL+C?

 

I tried adding an

 

 

do {

...

} until ($a -eq $b)

 

to set some arbitrary variables which would never equal each other but that didn't work.  I'd like to keep cycling through the pages in that list essentially.

 

EDIT: 

I quickly found out how to do an infinite loop.  Simply append 

 

  for (;;) {  ... scriptblock } 

To any scriptblock to make it loop infinitely.  In my shop we used this structure to build a list of SCOM web reports and general environmental health statistics which are cycled through on a number of monitors every few minutes.  Works great!


  • Edited by Stephen Owen Thursday, October 13, 2011 4:52 PM Adding Content
Free Windows Admin Tool Kit Click here and download it now
October 13th, 2011 7:39pm

I know this older, but can you post your script that uses the

           for (;;)

section, I am trying to get this to work but it keeps throwing errors. I don't know where to put it.

Thanks,

Eric

May 1st, 2014 1:33pm

Can you post your code that is throwing errors?  That might be the quickest way to get you a fix.

Free Windows Admin Tool Kit Click here and download it now
May 1st, 2014 2:37pm

Using the code above in a powershell console do this:

$ie | get-member

to get a list of methods and properties.  You can further drill down with

$ie.document | get-member

etc, etc for all the properties.

Here's a helpful link to the IE Document Object Model:

http://msdn.microsoft.com/en-us/library/hh772384(v=vs.85).aspx

And for the wait, I've found this is more accurate for some pages:

do {sleep 1} until (!$ie.Busy -and $ie.readyState -eq 4)

I found some pages will still be doing 'something' even though IE isn't 'busy'

May 1st, 2014 3:22pm

I should clarify that I don't know where to put the for(;;) command in the code.  I used the code as listed above, it works great, but only cycles though one time.

The author stated:

             I quickly found out how to do an infinite loop.  Simply append
             for (;;) {  ... scriptblock }

I have tried appending that to the end and it doesn't work, in fact I've tried putting it several areas amongst other things in failed attempts to loop the  {$ie.navigate($_) part.

I am not an expert at this stuff by any stretch,  but I can copy and paste with the best of them. :-)


Free Windows Admin Tool Kit Click here and download it now
May 2nd, 2014 2:15pm

It would actually be a prefix, not an append:

$ie = new-object -com InternetExplorer.Application 
$ie.Visible = $true

for (;;) {
  get-content "C:\listofurl.txt" | % {
    $ie.navigate($_) 
    do {sleep 1} until (-not ($ie.Busy)) 
    Sleep 10 # pause
  }
}

That will repeat the get-content and navigate to each of the urls in the text file indefinitely.

May 2nd, 2014 2:25pm

Put this in front of your code

for (;;) {

and put this after your code

}

Free Windows Admin Tool Kit Click here and download it now
May 2nd, 2014 2:26pm

That is a thing of beauty!  Thank you!  Works great for my NOC monitor project.
I could have sworn I tried putting that there, but I guess I messed up the exact placement.

set-ExecutionPolicy Unrestricted
$ie = new-object -com InternetExplorer.Application 
$ie.Visible = $true
$ie.FullScreen = $true
for (;;) {
  get-content "C:\NOC\urls.txt" | % {
    $ie.navigate($_) 
    do {sleep 1} until (!$ie.Busy -and $ie.readyState -eq 4)
    Sleep 45 # pause
  }
}

May 2nd, 2014 2:33pm

This all works well until the URLs in question contain iframes, at which point the script breaks and no new pages are loaded.  I've even tried leaving this as just a pure timer, i.e., leaving out the line  "do (sleep 1) until...", but the script seems to lose focus when multiple iframes are involved.  Any ideas?
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2014 12:07am

This all works well until the URLs in question contain iframes, at which point the script breaks and no new pages are loaded.  I've even tried leaving this as just a pure timer, i.e., leaving out the line  "do (sleep 1) until...", but the script seems to lose focus when multiple iframes are involved.  Any ideas?
May 29th, 2014 12:07am

This question has been asked and answered, please start a new thread and post the code you're working with.
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2014 6:14am

This question has been asked and answered, please start a new thread and post the code you're working with.
May 29th, 2014 6:14am

I believe my question belongs in this thread, as I'm inquiring specifically about the code in this thread and the fact that the code presented above only works in the most basic circumstances and doesn't handle some URLs.  For example, if you put http://www.securitywizardry.com/radar.htm as one of the URLs in your list, you'll find that the script halts on that page and will not progress to the next URL.  This occurs even when scrapping the IE state interrogation:

do {sleep 1} until (!$ie.Busy -and $ie.readyState -eq 4)

and going with only a sleep timer.

Anyone have ideas for how to make this work for most types of dynamic web pages?

Free Windows Admin Tool Kit Click here and download it now
June 2nd, 2014 6:30pm

I believe my question belongs in this thread, as I'm inquiring specifically about the code in this thread and the fact that the code presented above only works in the most basic circumstances and doesn't handle some URLs.

You should always start your own thread. You can link back to this thread if you wish, but adding a post to an already answered thread is not a good way to have anyone new see this.

The best method is to start a new thread, post your code, your errors, and everything you've tried so far.

June 2nd, 2014 6:59pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics