Showing posts with label Bing. Show all posts
Showing posts with label Bing. Show all posts

Saturday, November 12, 2011

Using the PowerShell ISE–two cool finds

I’ve been using PowerShell’s Integrated Scripting Environment ever since it was in beta. Despite being relatively slow to load, it sure beats using Notepad for simple script development/debugging. The colour coding alone makes it even more useful! I love how you can add functionality to the editor via object model. It’s neat how that object model is exposed inside PowerShell as the $ISE variable – and how easy it is to use it to add menu items (and keyboard short cuts for the menu items).

A freely available module that offers a lot of ISE customisation is the IsePack, which is part of the PowerShellPack mega-module issued by Microsoft as part of the Windows 7 Resource Kit. You can download the full PowerShellPack from http://archive.msdn.microsoft.com/PowerShellPack. The PowerShellPack module is actually a set of 10 sub-modules. You can import the entire module (Import-Module PowerShellPack) or the sub-components. In my ISE Profile file, I add the ISE pack in specifically (Import-Module IsePack). That in turn exposes me an additional Add-On menu item, ISEPACK. This menu contains a set of sub-menus which add a lot of features to the ISE.

My two cool finds are partly what’s in IsePack and what I could easily add to it. The ISEPack creates a number of functions based on the ISE’s object model. It then leverages those in additional functions that PowerShell associates with menu items and keyboard shortcuts when the module is imported. And since the module is just a text file – you can easily edit it and add more features.

The first cool find is the Search-Bing function, which is associated with a menu item (Add-ons/IsePack/Search-Bing) and a keyboard shortcut (Ctrl-B). The Search-Bing function uses a lower level function,  Select-CurrentText, that gets the text that is currently selected somewhere on the ISE', then pipes it to copy of IE which points http://www.bing.com/search?q=$_. Thus, if I have the text ‘ToString’ highlighed in an open editor window, and hit Ctrl, I get a Bing Search Page, like this:

image

 

The second cool thing was how easy it was to ammend the IsePack module to add a Search-Google function. In the IsePack.PSM1 file, there’s a fragment of code that implements the Search-Bing feature (and adds it to the menu) This fragement is part of a larger script, but here’s the starting poing:

"Search-Bing" = {
        $Shell = New-Object -ComObject Shell.Application
        Select-CurrentText | Where-Object { $_ } | ForEach-Object {
            $shell.ShellExecute("
http://www.bing.com/search?q=$_")
        }
    } | Add-Member NoteProperty ShortcutKey "CTRL+B" –PassThru

 

As you can see, Search-Bing is associated with a script block that first opens the currently configured Web Browser (FireFox in my case). Then it executes a Bing Search on the currently selected text. This results in the search window coming up. So how hard was it to add to add a Search-Google? Trivial as it turns out. I just added the following text directly below the Search-Bing definition:

    "Search-Google" = {
        $Shell = New-Object -ComObject Shell.Application
        Select-CurrentText | Where-Object { $_ } | ForEach-Object {
            $shell.ShellExecute("http://www.Google.com/search?q=$_")
        }
    } | Add-Member NoteProperty ShortcutKey "CTRL+Shift+G" -PassThru

 

Sadly, Ctrl+G was already taken by something (a puzzle for another day!), so I used Ctrl+Shift+G and that brings up something like this:

image

 

As I am currently working on my next Pluralsight course on Formatting with PowerShell, I’m finding a need to look stuff up in MSDN and these two functions sure are useful to me!

Wednesday, April 21, 2010

PowerShell Cmdlets Search via Bing

Microsoft this week released a new feature in the Bing search engine – a visual search of PowerShell Cmdlets. This is part of the Visual Search feature of Bing which allows you to search using visual images, versus just text. When you fire up the Visual Search , you will now see a “Visual Search” link.  You can then click through to see the PowerShell Cmdlets. Sadly, this is available currently only in the “en-us’ version of Bing, but it looks like this:

image

 

Along the left, you can see a number of categories (Top 12 Cmdlets, WMI Cmdlets, etc) as well as some ways to narrow down your search. I especially like the ‘Introduced in Version’ and ‘Remoting Uses’  As you can see in the above graphic, when you click on a cmdlet, you get more help information along the right, including basic cmdlet information and several links to more detailed help documentation. Although you can’t see it from the graphic above, this page seems to be generated by using WPF, so you get some pretty neat effects when you click on the left hand pane of this page!

Th PowerShell Cmdlets search feature is available on the US version of Bing only. Unlike Google, there seems no way to invoke country specific versions of Bing. You get what Bing works out to be your local variant. But with a little hacking, you can indeed get to the above page. The rather unfriendly URL is: http://www.bing.com/visualsearch?mkt=en-us&g=powershell_cmdlets&FORM=SGEWEB&qpvt=powershell#remoting=1&r=1. Alternatively, you can start at the Bing US home page and drill down from there (http://www.bing.com/visualsearch?mkt=en-us).

There will also be more cmdlets documented this way. I have no idea what the time table is, either for wider disbribution of this pretty cool feature, or when we’ll see more cmdlets being documented.

Technorati Tags: ,