{"id":124,"date":"2007-05-07T18:31:32","date_gmt":"2007-05-08T02:31:32","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/05\/07\/live-search-in-windows-powershell\/"},"modified":"2007-05-07T18:31:32","modified_gmt":"2007-05-08T02:31:32","slug":"live-search-in-windows-powershell","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/05\/07\/live-search-in-windows-powershell\/","title":{"rendered":"Live Search in Windows PowerShell"},"content":{"rendered":"<p>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:<\/p>\n<p><strong>. path\/LiveSearch<\/strong><\/p>\n<p>Then, get search results:<\/p>\n<p><strong>$hits = Get-SearchResults &#8220;PrimalScript&#8221;<br \/>$hits<\/strong> alone will display the hits<br \/><strong>$hits[0].title<\/strong> displays the first hit&#8217;s title<br \/><strong>$hits[0].Open()<\/strong> opens the first hit in a new IE window<\/p>\n<p>Neat, eh?<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"csharpcode\">Function Get-SearchResults {<br \/>    <span class=\"kwrd\">param<\/span>([string] $searchstring=$(<span class=\"kwrd\">throw<\/span> <span class=\"str\">&quot;Please specify a search string.&quot;<\/span>))<br \/>    $client = New-Object System.Net.WebClient<br \/>    [xml]$results = $client.DownloadString(<span class=\"str\">&quot;http:\/\/search.live.com\/results.aspx?q=&quot;<\/span> + $searchstring + <span class=\"str\">&quot;&amp;format=rss&quot;<\/span>)<br \/>    $channel = $results.rss.channel<br \/>    <span class=\"kwrd\">foreach<\/span> ($item <span class=\"kwrd\">in<\/span> $channel.item) {<br \/>        $result = New-Object PSObject<br \/>        $result | Add-Member NoteProperty Title -value $item.title<br \/>        $result | Add-Member NoteProperty Link -value $item.link<br \/>        $result | Add-Member NoteProperty Description -value $item.description<br \/>        $result | Add-Member NoteProperty PubDate -value $item.pubdate<br \/>        $sb = {<br \/>             $ie = New-Object -com internetexplorer.application<br \/>            $ie.navigate($this.link)<br \/>            $ie.visible = $true<br \/>        }<br \/>        $result | Add-Member ScriptMethod Open -value $sb<br \/>        $result<br \/>    }<br \/>}<\/pre>\n<style type=\"text\/css\"><\/style>\n","protected":false},"excerpt":{"rendered":"<p>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:<\/p>\n<p>. path\/LiveSearch<\/p>\n<p>Then, get search results:<\/p>\n<p>$hits = Get-SearchResults &#8220;PrimalScript&#8221;<br \/>\n$hits alone will display the hits<br \/>\n$hits[0].title displays the first hit&#8217;s title<br \/>\n$hits[0].Open() opens the first hit in a new IE window<\/p>\n<p>Neat, eh?<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}