Use Windows Explorer as a Code Snippet Manager (for VBScript, PowerShell, .CMD, .BAT, etc) by Configuring Windows Libraries, Windows Search and File Previews Print E-mail
Written by Darwin Sanoy   
Monday, December 10, 2012 5:27pm

Most scripters I know are code sample junkies – the learn by hacking away at existing scripts on the web and one’s they have collected.  Recently I’ve been on the hunt for a easier way to store, search and find code snippets.  I found a lot of stuff, but nothing that satisfied.  As I was searching I realized by configuring three different areas of Windows, I could have a pretty nice snippet manager right in Windows Explorer.  Some of these changes you will want to make even if you don’t actively manage snippets! When looking around I had what I thought were some basic requirements – yet stand alone snippet managers as well as those built-in to editors did not satisfy.

Here were my requirements:

  1. Can be leveraged by a team without dictating which editor they use.
  2. Works for VBScript (.VBS), PowerShell (.PS1) and if possible Windows Shell Scripts (.CMD/.BAT).
  3. Can work with standard files on disk (does not require snippets to be stored in a database, does not have it’s own file format – who wants to reformat or explicitly save samples into another format when most of them come to us as files?).
  4. Indexes the files (PS Pad has a lightning fast “Search in Files” – but it would take a while on multiple network based sources.
  5. Organization into folders or something similar.
  6. Multiple file locations can be indexed.
  7. Free.

I found a variety of interesting options, but I was surprised at the amount of overhead I was expected to invest in adding new snippets of my own.  I have many samples and snippets I have written as well as many I’ve collected and they all reside on disk as regular scripts.  I’m really not interested in hours worth of time entering them into a special database or a new file type on disk.

I think that all tools should support indexing existing scripts on disk and do some intelligent parsing and indexing.  Why not consider every script comment as part of the “description”?  Maybe specify a way of configuring keywords in comments that makes it easier for the tool to index – but when those cues are found – index all the comments.

One thing that was particularly disappointing was the lack of VBScript support within PowerShell editor integrated snippet managers.  PowerShell is obviously the future of Windows Scripting – but I still have to work with a lot of legacy VBScript and would like to do that in same editor.  The top two paid editors are notable exceptions – sporting full VBScript and Powershell support.  Those are PrimalScript and Admin Script Editor (ASE) – but these are not free.

When I select a tool I always gravitate to the solution that introduces the fewest encumbrances to how I already work.  I think most of us do this even if we don’t know it.  One effect that may be at play here is that those who create code sample and snippet managers are developers who code all day – which makes it worth their while to spend more time managing their code collections.  Administrative scripting is generally a more occasional activity and make too much time spent on managing samples and snippets feel like an impediment.

By doing several simple configuration changes to Windows we can create a fairly reasonable code sample and snippet manager.

1. Configure Windows Explorer Previewer To Show Inside Your Code Files Without Having to Open Them.

The first change is to configure Windows built-in plain text previewer to show files you wish to see inside of without opening them.  I cover this item first because the functionality is very useful even if you don’t need to manage code samples and snippets.

Usually there are some guid based registry keys that must be configured to enable the plain text preview (gory details here: but the free utility “PreviewConfig” makes it extremely simple.  The screenshot shows how to configure Windows to show the contents of a .PS1 file:


Select or Type the File Extension, Select “Plain-text” and Click Apply

In this case the .ps1 file extension appeared in the list of extensions.  In cases where the file extension does not appear in the list (e.g. “.XML”), simply type it in the textbox above the extension list, select “Plain-text” and click “Apply”.  The file type will be added to Windows as well.

I have my system configured to preview the following extensions: .VBS, .PS1, .CMD, .BAT, .XML, .OSD (App-V / XML), .SPRJ (App-V / XML). This one step alone saves me a lot of time because I spend many minutes a day explicitly opening these file types for a read-only peek. Now I can just click them and see the insides. The previewer even has a vertical scroll bar to see the whole file.

You can be download PreviewConfig from here:

2. Configure Windows Search to Index the Content of Your Code Files.

Windows search can be configured to index just the file names themselves or index the contents of files.  Windows can easily index plain text, so once again built-in functionality can be used to leverage.  This configuration is per file extension (just like the previewer).


From Control Panel, Click Indexing Options, Then Click Advanced


In Indexing Options, Select File Types, Select the Extension
and Click Index Properties and File Contents

3. Create One or More Windows “Libraries” To Point to Your Code Locations.

Creating libraries has two primary benefits: *) Aggregating multiple different locations, *) Limiting your search to just those file locations, *) Automatically configuring Windows Search to index those locations (if local).

You can create a library per file type, or if you mix all your samples in one library, you can use a Windows Search qualifier to focus on a file type (e.g. “type:.vbs”)

managingtheenterprisewindowsdesktopwithpowershelltitlegraphic320 For more explanation and updated Ready-To-Run code for this topic, check out our video course "PSH-205 Managing the Enterprise Windows Desktop with PowerShell"
[ Free for a limited time ]


In Windows Explorer, Right-Click Libraries > New > Library
Name the New Library and Click Enter


Edit the Properties of the New Library


Click Include a folder… then Browse to a folder
and click Include Folder.

Under Optimize this library for, select Documents.

When a folder is added to a Library it is also automatically added to your local search folders to index – this can be viewed in Control Panel > Indexing Options…


Non-indexed Network Folders Show This Message

Local folders that are not index can be added using the Modify button in the "Indexing Options” control panel icon. 

If you receive the not indexed error for a server path, there are three options:

  1. Make the folder available offline (probably not suitable for most situations as it syncs the entire network location to your local machine).
  2. Index the folder on the server (to do this, make sure the folders are indexed on the server using “Control Panel => Indexing Options”, you may need to first install indexing services under the “File Server” role)
  3. Symlink hack to get your local machine to see a server location:  There are some reported challenges with the search results using this method.

4. Configure One or More Editors.

We won’t be covering details in this tutorial, but you can configure one or more editors on the “Open With…” submenu so that your sample and snippet library will be able to interface with your favorite editor.

5. Doing Searches

For searches, simply use the regular Windows search prompt in Windows Explorer.  There is only one special trick for searches.  If your sample folders have more than one type of file in them, then you can use the “type:” qualifier – for example “type:=.ps1 <search term>” to keep your search focused on one type of sample code.


Click in the search prompt to see filters and click Type:


After selecting Type:, the list of file extensions will pop-up, select the desired extension.


Type the search term.

I did see some nice features that I’m be leaving behind for my poor man’s snippet manager, here are some of them:

  1. Meta data assignment (e.g. “Description”) and searching (although we can get around that with the Windows Explorer version).
  2. Automatic extension of the repository to one or more web-based repositories. (personally I find rifling through thousands hits on user submitted samples less productive than Googling).
  3. Term highlighting on files previews that contain hits. (Many snippet managers don’t have this anyway.)
  4. Downloading or directly searching online repositories of scripts.

Any Developers Listening Out There? I’d Pay To Have This Enhanced.

There are a lot of cool ways to extend the Windows Shell and Search capabilities.  I sure would love to see an add-on to Windows that did syntax highlighting in the preview (found a free one that was broken), created and indexed metadata fields by intelligently using formatted comments in the script (so they always go with my script and can be read without the add-on).  Of course Windows already supports configuring one or more of your favorite editors against each file type.


Add comment

Security code