Main menu:


Site search

My Wife’s Website

Recent Posts

Categories

Archives

August 2007
S M T W T F S
« Jul   Sep »
 1234
567891011
12131415161718
19202122232425
262728293031  

Links:

Meta

Improving Surfing the Web the PowerShell Way

I have just started learning PowerShell and I am looking forward to learning a new language and it isn’t going to be Ruby (been there, done that).  I have been reading the book “Windows PowerShell in Action” by the Bruce Payette.  this seems to be THE book on PowerShell.  It is a very easy read so far.

Aaron, a friend at work, will be speaking at the Indianapolis .NET Developer’s Association this coming week.  In his post about it, he gives a link to a script written by Jeffery Snover which gives an easy way to kick off a IE 7 browser window using some predefined favorites.  For example, if he starts:

PS> Oie v,gtr,dr

It will bring up a browser window with three tabs and three different pages. The definition of “v”, “gtr”, and “dr” are hardcoded in the script in a hashtable. When I first saw this it was screaming to me, “Hardcoded urls? Why not use favorites? That would be much more user friendly!”

So at 11:00 PM at night when I know I should be going to bed early anyway, I start hacking away at the script. Here is first contribution to the PowerShell community. To use my changes create a PSLinks folder in the favorites folder. The name of the shortcut will be the name to pass into the script.

function Get-InternetShortcutUrl($path)
{
if (Test-Path $path)
{
(Select-String BASEURL $path).Line.Split("=",2)[1]
}
}

$Script:OutIE = $Null
function Out-IE ($url, [Switch]$Reuse)
{
$favdir = "$env:userprofile/favorites/pslinks"
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 "-?"))
{
dir $favdir | Sort Name | Format-Table `
@{Expression={$_.Name.Split(".",2)[0]};Label="Name";Width=10},`
@{Expression={ Get-InternetShortcutUrl $_};Label="URL"}
return
}

$navOpenInBackGroundTab = 0
foreach ($u in @($url))
{
$MappedUrl = Get-InternetShortcutUrl "$favdir/$u.url"
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
}
$Script:OutIE.visible=1
}
Set-Alias oie Out-IE

Comments

Comment from Jeff Moser
Time: August 5, 2007, 7:26 am

Any plans on making cmdlet friendly interfaces to your CLR code?

Write a comment