Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


November 06, 2009

Retrieve Information from Open Browsing Sessions

PowerShell script makes it quick and easy
RSS
Subscribe to Windows IT Pro | See More Internet Explorer (IE) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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):

while($true){
  sleep 60; $ies |
  %{$_.Refresh()}}

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.

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

PowerShell 201 - eLearning Series with Paul Robichaux

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement