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.

Convert JSON or CSV to a PowerShell Class

There’s a new keyword in PowerShell v5.0, it’s for creating classes directly in your PowerShell scripts. Check out Introduction to PowerShell 5 Classes.

Verify Incoming Data

One application of PowerShell classes is the ability to simplify verification of incoming data. For example, you may have comma separated input that looks like this:

Line 3 clearly has bad data. If you use ConvertFrom-Csv, it will happily create PowerShell objects on the fly but both the name and age property will be defined as strings, and 10a is a string. We need a little more safety.

Here is a class Person that strongly types the properties name as string and age as an int.

Putting this together let’s you detect data errors early.

Running the above generates this error.

This is a great way to do pre-flight checks on incoming data to determine if there are issues.

Expand the DataSet

What if the input data has more properties:

Working up a PowerShell class by hand for this can be tedious and error prone. So, let’s automate it with ConvertTo-Class


ConvertTo-Class is a PowerShell module I published, and it’s on the gallery. It automates creating a PowerShell class from either CSV or JSON text data. ConvertTo-Class determines both the name of the property and the actual data type of the data.

Quick, Easy and accurate!

ConvertTo-Class infers the correct data type for the properties age,zip, and rent.

The class is ready to go. You can save it to a file and dot source it or you can do an Invoke-Expression on it and use it immediately.

Auto Detects JSON Too

The same ConvertTo-Class function atuo detects JSON and produces the same class as it did with the CSV data.

Here is the same class. Notice you can use the -ClassName parameter to override the default class name of RootObject.

Plus, ConvertTo-Class Handles Multiple Classes

Here is sample JSON that has multiple classes. ConvertTo-Class detects and generates each class with it’s properties.

Here’s the code generated PowerShell classes, wired up and with the correct data types.

Generate C# or PowerShell Classes

PowerShell class syntax is the default output. You can also generate classes for use in C# with the -CodeGen CSharp parameter.

In an upcoming post, you’ll see how you can easily specify your own code generation “rules” to create constructs for other languages or purposes.

In Action Video

I’ve also published two PowerShell scripts that let you paste JSON or CSV to classes from the clipboard in either the console, using PSReadline or from ISE via an addon.


Grab the PowerShell

You can get ConvertTo-Class from the PowerShell Gallery or on my GitHub repo.

Love the quick one off automation you can do in PowerShell

I use markdown for lots of things. Note taking, blog posts, read me files for my GitHub repos and more.

Typically I launch MarkdownPad, start typing and then do a File|Save, navigate to the directory where I want it and save it.

Too Much Work

That workflow opens itself to lots of missteps. Eye hand coordination problems, fat fingering the directory where I want it saved, etc.

So, let’s whittle that down to 10 characters (less if you use tab completion) plus the name of the file.

New-MDFile blogEntry

The function adds the '.md' extension, then creates it, with the proper encodoing and finally does an Invoke-Item on the file name so it launches MarkdownPad with it ready for editing.


On another note, I’ve been working with TypeScript recently. Often, I need to find text across multiple files. The typescript files are organized across directories and in subdirectories.

Rather then repeatably typing ls . -r *.ts and piping it to Select-String with the pattern you’re looking for (too much work). You create a function and combine these operations into one. The search string is optional, fts will return a list of typescript files if it is not specified.

fts showInformationMessage

Question: How would you adapt this to work with PowerShell files? C# files? Other files?

PowerShell ConvertFrom-String: Serious Text wrangling

There’s a new PowerShell cmdlet ConvertFrom-String released with PowerShell v5.0. There are a bunch of write ups on using this cmdlet and I want to show how it makes quick work of HTML source.

HTML Source

Sometimes you’ll get html that looks like the snippet below (remember, it could be hundreds an hundreds of lines of HTML). So editing/transforming it by hand would take quite some time.

The Transform

Let’s say we wanted to go from the HTML above, to this:

I’ve written code (or used a macro recorder in a text editor) to find the first ‘>’, delete the text to the left, find the ‘(‘ grab the text I want, etc.

The challenge is, not all the people I work with know how to do this. Plus, there are many other (mundane) text reformatting tasks that people go through every day.

Enter ConvertFrom-String

The key here is the $template on starting on line 17. I’m using ConvertFrom-String to do example-driven parsing. The template provides the example (hints to ConvertFrom-String on what I want extracted).

I put curly braces around the data I want to extract, and give it a name Item and Count. The * tells ConvertFrom-String this should result in multiple records.



The data is piped to ConvertFrom-String, parsed an then piped to ForEach which does the final transform.

That, is slick and easy.

Note: I’m providing the data and template in the code. Both the data and template can be in separate external files so script could be run to do transforms over many inputs.

Check Out ConvertFrom-String Buddy

I created a GUI (Using PowerShell and WPF), you can get the script HERE.

It lets you quickly and easily experiment with ConvertFrom-String.

Paste the data you want to transform in the data text box (on the left). Start typing the example template in the template text box (on the right). As you type, you’ll immediately see results in the result text box.

Plus, it generates the PowerShell code as you go. You can copy that to the clipboard and save it as a script for later.