Surfing the Web the PowerShell Way

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: