Full-Text Search: PowerShell meet Lucene

Bruce Payette, co-founder of PowerShell, gave a talk on integrating full-text search using Lucene with PowerShell at the PowerShell Summit.


So I did a little refactoring and wrapped it in GUI, this is all PowerShell.

In Action

It indexed the content of 2500+ files in ~2 seconds.

Index and Search

Type in the name of the directory to be searched, including a filter, c:\posh\*.ps1, press enter and it will recursively search the directory for all ps1 files and index the contents, keeping the index in memory. You can also search multiple directories with different filters. E.g. c:\temp\*.cs,c:\test\*.ts,c:\arm\*.json

Then, you can search for a term across everything that was indexed by typing in the Query box and pressing enter.

What is Lucene?

Apache Lucene is a free and open-source information retrieval software library, originally written in Java by Doug Cutting. It is supported by the Apache Software Foundation and is released under the Apache Software License.

Who uses Lucene

  • Apache SOLR (Used by OMS Operational Insights)
  • Elastic Search (everybody uses this)
  • CIteSeerX
  • Apple
  • 7digital (digital media)
  • Comcast
  • Disney

On GitHub

Grab it all from my GitHub Repo.

Paste JSON as a PowerShell Class in Visual Studio Code

The PowerShell extension for Visual Studio Code just got way cool.

First, we got a $profile. It lets you customize your environment and add session-specific elements to your PowerShell Visual Studio Code session.

Second, we got a way to interact from PowerShell directly with the vs code editor.

You use Register-EditorCommand to register a PowerShell function|scriptblock. In the PowerShell script you can set it up to a take a “context” parameter that gets passed in. This parameter contains a reference to the vs code editor (in the future this reference will surface more features), you can now do things like InsertText into the active file.


I took my existing PowerShell module and added this handful of code to connect it to Visual Studio. ConvertTo-Class takes a JSON string, figures out it structure plus data types and code generates a PowerShell v5.0 Class.

In Action

If you have PowerShell v5.0 installed, you can grab the ConvertTo-Class module from the command line like this Install-Module ConvertToClass

Edit your PowerShell VS Code $profile and add Import-Module ConvertToClass.

Start VS Code. In VS Code you can edit both a JSON file and PowerShell file and have a rich editing experience for each.

Here, I’m copying a JSON snippet of an Azure Resource Management (ARM) Template, then switching to a PowerShell file and pasting it as a PowerShell Class.

That’s the quick tour. PowerShell module authors just got some really cool integration tools for Microsoft’s new modern editor, Visual Studio Code.

I can’t wait to see what the community starts to add to the ecosystem.


Check out these links for more info.

PowerShell is a Query Language for JSON

PowerShell, as is, has all the tools you need to query JSON and then reshape, re-purpose it to what you need.


Who Moved the Cheese – Microsoft’s new editor “Visual Studio Code”

Microsoft VS Code reached the 1.0 milestone and announced Version 1.0 of Visual Studio Code.

It is code editing redefined. Plus, PowerShell support for syntax highlighting ships in the box, and you need to install the extension (see VS Code Extensions to see how to) to get the rest, intellisense, debugger and much more.

I’ve been lucky to be involved with the PowerShell Editor Service, I’ve made contributions to it and have be around many great conversations about features now and to come.

Here is the Expand Alias feature I contributed.

VS Code

VS Code launched a year ago, there have been 2 million installs of VS Code. There are more than 500,000 people actively using VS Code each month.

  • Intelligent editing
  • Powerful debugging
  • Built-in Git support
  • Hundreds of extensions

What started as an experiment to build a production quality editor using modern web technologies has blossomed into a new kind of cross-platform development tool, one that focuses on […] productivity by centering the product on rich code editing and debugging experiences.

Really Cool

Besides the fact that I can a huge amount of work for PowerShell in VS Code, I found this next part really cool.

I’ve been doing more work in Azure and after I did a PaaS deployment of an App Service, I exported the configuration from the Azure Portal to a zip file.

The zip had five files, deploy.ps1, deploy.sh, DeploymentHelper.cs, parameters.json, and template.json. I extracted the files and then typed code . to launch vs code telling it use the current directory as my “project”.

Here’s where it gets cool, there are 4 different file types in that Azure export. A PowerShell file, Linux Shell file, a C# file and JSON files.

NOTE: I have these two Visual Studio Code extensions installed C# and Azure Resource Manager Tools.

From VS Code, I clicked on each file and VS Code provided me syntax highlighting, and intellisense for the PS1 and C# files and for the JSON files, because they are ARM templates, the Azure Tools extension gave me intellisense based on the ARM schemas defined.

Check it out

Editing four different file types, supporting syntax highlighting and more.

All in one place I could easily edit each file and in the case of the PowerShell script, I could run it from vs code, debug it and get all the intellisense I expect from other environment.


VS Code Extensions

It is super easy to get these extensions in your environment too. After installing vs code, run it. For example, from a PowerShell prompt type code and press enter. After it launches, press F1. This will give you a dropdown at the top, it’s called the command palette, something you’ll use a lot. Next, type ext inst, press enter. This will query the Visual Studio Code Marketplace for published extensions.

When the list is returned, you can start typing the name of the extension you want, the list will update with matches. Type powersh. Next to the highlighted selection, you should see some blue boxes, you can click on the ReadME, License to read about these details or the Cloud and Arrow to download and install the extension. After it is installed, VS Code needs to restart and will prompt you if you want to do it now or defer to later.

Once installed and restarted the extension, when you edit a PowerShell file you’ll have even richer features at your fingertips. Repeat this to install the C# and Azure Manager Tools extension. Also, browse through the list to see what other extensions meet your needs.

VS Code Pandoc

This is a vs code extension that I wrote and published. I work a lot with markdown files. Visual Studio Code not only supports editing these files, it also has a live preview of them.

I ran across a free tool called Pandoc it renders markdown into amazing number of formats. The ones I’m interested in, PDF, Word Docs and HTML

NOTE: If you want to render to PDF you need to install MiKTeX for pandoc to generate it.

Install Follow the instruction in VS Code Extensions, search for pandoc and install.

In action

Here’s what the interaction looks like when rendering markdown to other formats in VS Code.

Check out vscode-pandoc in the market place.

More Productive

Visual Studio Code is a very impressive editor. For PowerShell, I’ve opted to do more of my PowerShell scripting in vs code. Yes, there are pieces missing, but not for long. Plus, if you are editing more than one type of file in your day, it’s worth checking out vs code. The sooner you do, the sooner you’ll find the moved cheese and be more productive.

NOTE: We haven’t even talked about how easy it is to create vs code extensions to fit your workflow.