Category Archives: Scripting

Friday Fun: Search Me

magnifying-glass-text-label-search I’ve been working on a few revisions and additions to my ISE Scripting Geek module. Even though what I’m about to show you will eventually be available in a future release of that module, I thought I’d share it with you today. One of the things I wanted to be able to do was search Google (or Bing) from within the PowerShell ISE.

If you research search techniques or APIs for sites like Google and Bing, you’ll quickly get swallowed up in the miasma of JSON, SOAP, XML and mind-numbing examples. Although you might enjoy this sort of thing, I was hoping to find something much, much simpler. After all, I’m not going to be creating complicated search queries. I’m going to want to search for a simple term or phrase like “powershell remoting” or “Invoke-Webrequest”.

For Google, it is this simple to create a URL:

To use Bing, it seems it helps to include your culture which you can retrieve with Get-Culture.

In either case I now have an appropriate URL ready to go into my default browser. I can’t guarantee this will work for everyone, but it is as simple as this command:

I’m actually using the alias for Start-Process but in this case I don’t mind. Windows will switch to my browser and open the URL in a new tab. To make all of this a bit more flexible I put together a simple function.

The function needs a string of text to search for and a search engine. I’ve set a default to Google. You’ll also see that I’ve included parameter validation so that you can only use a value in a pre-defined set. To make the function a bit more interesting I also included Yahoo. I’ve used a Switch statement to determine how to construct the url. You could use this function from either the console or the PowerShell ISE. I suppose in terms of PowerShell this is a “low-tech” approach but it works and meets my needs.

To plug this into the ISE, you need to dot source the function in the ISE. Then if you want, you can add it as a menu item.

This will add a menu shortcut to the Add-Ons menu called “Search Internet”. I’ve also included an optional keyboard shortcut ALT+S, but you can define anything that isn’t already being used. When the menu item is invoked, it will run my Get-SearchResult function and use the currently selected text for the -Text parameter. The net result is a Google search for whatever I have selected in a script file. If you prefer Bing, I’d simply modify the function and set it as the default.

This isn’t rocket science but hopefully makes your PowerShell experience a little more efficient. You are welcome to try this now, or wait for the next version of the ISE Scripting Geek.

Have a great weekend.

Friday Fun: Updated ISE Scripting Geek Module

geek A few years ago I published a module with a number of functions and enhancements for the PowerShell ISE. This ISEScriptingGeek module has remained popular over the last few years. But I wrote it for PowerShell v2. I have also come up with a number of new additions to the ISE that I use to make scripting easier. So I have gone ahead and updated the module.

The new module includes most of the original features, many of which are added to a custom add-ons menu.

scriptinggeek-addon-menu

To use the module, import it in the ISE or in your ISE profile script. Once imported you can view all of the commands.

Most of the commands will have help. I’m not going to go into detail about every command and menu option. I incorporated my scripting help module as well to provide documentation on some of the validation attributes. I think you should load up some test files and try things out.

The final thing I have done is to include some ISE theme files. To import them, go to Tools – Options and click on Manage Themes. Click on Import and navigate to the Themes folder in the module directory (…\documents\WindowsPowerShell\Modules\ISEScriptingGeek\Themes). You should see 3 files. Import one or more, select it and click OK.

grayscaletheme

monoyellow-theme

vim-theme
This version requires PowerShell 4.0 or later. DownloadISEScriptingGeek-v3.1 and extract to your modules directory.

If you have questions or run into a problem, feel free to post a comment. I especially would love to hear about your favorite features from the module.

Enjoy and happy scripting.

Friday Fun: Another Christmas Prompt

christmastree In last week’s Friday Fun post, I shared with you a PowerShell prompt that would display a festive Christmas countdown clock. This week I have another holiday related prompt function. This one is pretty straight forward and is not that much different from the default PowerShell prompt function.

I included some logic so that my customization only happens during the month of December and before Christmas. The prompt changes the background color of your console between DarkRed and DarkGreen. The first time you run it, the prompt will randomly select a color. You might want to run Clear-Host, or CLS after loading the prompt.

After that the background color will toggle leaving you with an effect like this:

christmasprompt2014-redgreen

It is interesting to see how different commands write to the console. You could even combine both of my prompts if you are in an especially festive mood.

christmasprompt2014-everything

There’s probably no practical value in this other than having some fun and maybe understanding some PowerShell scripting concepts. Hope your holiday shopping is going well. Have a great weekend.