Live Search in Windows PowerShell
This was just too cool not to share: Put this function into a PowerShell script file named LiveSearch.ps1. Then, dot-source the function into the shell:
. path/LiveSearch
Then, get search results:
$hits = Get-SearchResults “PrimalScript”
$hits alone will display the hits
$hits[0].title displays the first hit’s title
$hits[0].Open() opens the first hit in a new IE window
Neat, eh?
Function Get-SearchResults { param([string] $searchstring=$(throw "Please specify a search string.")) $client = New-Object System.Net.WebClient [xml]$results = $client.DownloadString("http://search.live.com/results.aspx?q=" + $searchstring + "&format=rss") $channel = $results.rss.channel foreach ($item in $channel.item) { $result = New-Object PSObject $result | Add-Member NoteProperty Title -value $item.title $result | Add-Member NoteProperty Link -value $item.link $result | Add-Member NoteProperty Description -value $item.description $result | Add-Member NoteProperty PubDate -value $item.pubdate $sb = { $ie = New-Object -com internetexplorer.application $ie.navigate($this.link) $ie.visible = $true } $result | Add-Member ScriptMethod Open -value $sb $result }}
May 7th, 2007 at 9:32 pm
Isn’t NET great?
Doesn’t PowerShell make it even better?
I can still remember the old days when all those admins and developers were dissing NET technologies.
June 13th, 2007 at 3:44 am
Old days?! Some still are! Even when watching the Power of the Shell with PowerShell, they just don’t understand. Just like the cranky addicts on the streets.