Surfing the Web the PowerShell Way

Rate This
  • Comments 13

I spend a lot of my time in the command line (surprised?). That said, I also spend a lot of time surfing the web. Here is a script that I wrote that lets me surf the web from PowerShell:

UrlTemplateMap = @{
"bs" = "{0}&ie=UTF-8&scoring=d"
"dr" = ""
"verb" = ""
"v" = ""
"ps" = ""
$Script:OutIE = $Null
function Out-IE ($url, [Switch]$Reuse)
if ($Script:OutIE -eq $null -OR $Script:OutIE.Application -eq $null -OR !($Reuse))
$Script:OutIE = New-Object -Com InternetExplorer.Application
if ((!$url) -OR ($url -eq "?") -OR ($url -eq "-?"))
$urlTemplateMap.GetEnumerator() |Sort Name |Format-Table @{Expression={$_.Name};Label="Name";Width=10},Value

$navOpenInBackGroundTab = 0
foreach ($u in @($url))
$templateUrl = $u
$MappedUrl = $UrlTemplateMap.$u
if ($MappedUrl)
$templateUrl = $MappedUrl

# Use the Template and $args to generage the final URL
$realUrl = $templateUrl -f $args
$Script:OutIE.Navigate2($realUrl, $navOpenInBackGroundTab)
$navOpenInBackGroundTab = 0x1000
Set-Alias oie Out-IE

This allows me a quick and easy way to navigate to my favorite URLs (I've included a subset of the ones I use). I put this into my profile file and then whenever I want to I can just type something like:

PS> Oie v,gtr,dr

And it will bring up IE (this is coded to Version 7 of IE) with 3 tabs for the corresponding URLS. This can also use parameterized URLS. For instance, I use google's blogsearch which takes a parameter for the search term. To search blogs for PowerShell I do this:

PS> Oie bs Powershell

This brings up a new window with all the blogs that have PowerShell in them. If I want to reuse an IE window, I use the –REUSE flag.

PS> Oie bs WINRM -reuse


Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:
Visit the Windows PowerShell ScriptCenter at:

Leave a Comment
  • Please add 7 and 4 and type the answer here:
  • Post
  • Looks like that UrlTemplateMap doesn't work because I get the term 'UrlTemplateMap' is not recognized... so the shortwords dont work.

  • Would you mind showing an example of how you might use powershell with mshtml?

    Maybe navigate to and fill in the search box and click ok?


  • hmm is there a way to specify different urls for different tabs in a new browser?

  • Ed:

    The .NET Framework offers great support for HTTP scripting. See:


  • Ed:

  • Karl:

    $ie=new-object -com internetexplorer.application




    "0x0800" will cause a new tab to open for $url2.

  • Karl,

    I just noticed that Jeff had something to open pages in different tabs.

    What exactly were you looking for?  To open pages in *specific* tabs like tab #1, #2, etc.?

  • I made a slight improvement to your script by using favorites in a PSLinks favorites folder to define the mapping instead of a hashtable.  See:

  • Is there any way to click urls, buttons, assign values to textboxes etc in a web form?

    I saw somewhere to assign values to test boxes, [get-inputElement $ie 'TextBox1'] is used. what if there is no id to the control? how to locate it. Does powershell support accessing controls via DOM?

  • I'll be using this as a method of keeping my IIS/.net sites warm, so users won't get the initial compile hit.


  • I just went to use it and found

    the 1st line needs the $

    UrlTemplateMap = @{


    $UrlTemplateMap = @{

    to work:)

  • Hi all,

    I am researching powershell

    I need to do the following things. I want to know whether I can do it by powershell.


    1. access a website: http://website/****.aspx

    2. the website will return a xml

    3. I need to analyze the xml and do some logic

    can I ?

  • You missing the '$' on line 1.  UrlTemplateMap should be $UrlTemplateMap, yeah?

Page 1 of 1 (13 items)

Surfing the Web the PowerShell Way