Retrieve Information from Open Browsing Sessions

PowerShell script makes it quick and easy


I occasionally want to hang on to some URLs that I've retrieved in a Microsoft Internet Explorer (IE) browsing session for later reference. Although you certainly can save and re-open tab sets of URLs on systems running IE 7.0 and later, you don't have any portability and you certainly can't save the information as a reference to browse through later on. I wrote a couple of PowerShell scripts to solve these browsing problems.

The first script, Get-IEUrl.ps1, lets you quickly retrieve information about the current browsing session for reuse later on. If you run Get-IEUrl.ps1 with no arguments, you'll get a list of the URLs for all the open web pages, as Figure 1 shows.

Figure 1: Getting the URLs for the web pages in an open browsing session (click to enlarge)

You can copy and paste these URLs for use elsewhere, or even send them to a file using a command such as

Get-IEUrl | Set-Content sites.txt

What's handy about saving the URLs to a file is that you can then use the second script, Start-IEUrl.ps1, to pull up the set of web pages. To do this, you'd use a command such as

Get-Content sites.txt | Start-IEUrl

Reviving the URLs this way doesn't necessarily give you what you had originally. Each URL will be in a separate IE window, even if you have tabbed browsing enabled. Still, it gets you back to the original web pages.

Get-IEUrl.ps1 has three optional arguments: -Location, -Content, and -Full. If you use the -Location argument like this

Get-IEUrl -Location

you'll get a list of the web pages' titles along with their URLs, which is useful if you want to save the items as references. Figure 2 shows some sample output that's been sorted with the Format-List cmdlet.

Figure 2: Getting URLs and page titles for the web pages in an open browsing session (click to enlarge)

If you use the -Content argument like this

Get-IEUrl -Content

Get-IEUrl.ps1 will output the title, URL, and content (text only) of each open web page. You can view this output onscreen, but I included this argument so I'd have an easy way to get information from web pages into a text file or printout for use offline.

Finally, if you use the -Full switch in a command such as

$ies = Get-IEUrl -Full

Get-IEUrl.ps1 returns the IE objects for all open web pages and stores them in the $ies variable. This lets you use the script as a starting point for performing other tasks in IE. What you can do depends to a great extent on your knowledge of IE. Let's look at a couple of simple examples.

The following code uses the IE objects stored in the $ies variable to refresh the open web pages every 60 seconds until you issue a break command (Ctrl+C in PowerShell):

  sleep 60; $ies |

If you want to print all the IE web pages captured in $ies, you can use the command

$ies | %\{$_.ExecWB(6,1)\}

Note that a Print dialog box will pop up for each web page. You can also bring up the Save As dialog box for each web page in $ies using the snippet

$ies | %\{$_.ExecWB(4,1)\}

Get-IEUrl.ps1 and Start-IEUrl.ps1 exploit only a couple of the capabilities of the IE automation model. If you're interested in exploring more things you can do with IE from PowerShell, try using Get-IEUrl.ps1 with the -Full argument, then use the Get-Member cmdlet on the returned IE instances. You can get more information about the IE object model from MSDN's "The Internet Explorer Scripting Object Model" web page.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.