Hidden Capabilities of PowerShell ISE IntelliSense

with 1 Comment

I do not program in PowerShell daily, but at least once or twice a week. Even though I am far from an expert on the matter, I would like to think of myself as a guy that knows the available commands.

Normally I have used the PowerShell ISE that comes bundled with Windows Management Framework to edit my scripts. As of late I have been looking around for another IDE, but have not found any that I feel lives up to my expectations.

I have come to realize that of the capabilities that I value the most, code completion (or “IntelliSense” as Microsoft calls it) is the most important. When I know the syntax it is relieving to know that what I write is correctly spelled. When I do not know, it is convenient to not have to spam the command prompt with the Get-Command and Get-Member cmdlets.

Powershell ISE is frankly a quite crappy text editor, but I think it has the best code completion of all PowerShell editors out there. That feature alone makes it a winner.

How it use PowerShell ISE IntelliSense

The IntelliSense menu is often invoked automatically when you write. But if you for example accidently close it, you can get it back by hitting Ctrl + Space.

An example of Powershell IntelliSense

What also works is hitting tab to complete the word to the top suggestion of what is in the IntelliSense list. If it is not what you want you can continue hitting tab to cycle through the suggestions.

This works on cmdlets, paths, variables, properties and classes of .Net instances, DSC-configuration, and what not. I bet that every PowerShell developer out there are aware. But what at least I did not know of until today is the following two.

Command history

If you write # followed by Ctrl + Space you get a list of the latest commands which were run in the console.

Command History with Powershell IntelliSense

This is ideal for inserting commands in your script that you have tested out in the console first. Or when writing commands in the console, you can get the history by other means than hitting the arrow keys repeatedly.

Completion of type namespace

As a .Net developer I am used to be able to include all types in a namespace of a resource with the using-statement. Unfortunately, there exist no equivalent in PowerShell. This was a real PITA. At least for me, up until today.

Powershell IntelliSense can type out the namespace of a type for you. Simply write the class name followed by Ctrl + Space and magic happens.

Type Namespace Completion with PowerShell

In this case [messagebox will be expanded to [System.Windows.Forms.MessageBox. Not that I actually would like to use a WinForms message box in a PowerShell script, but this is just a stupid example.

To use this functionality with class libraries you have written yourself you need to first import them with either Add-Type or [System.Reflection.Assembly]::Load*-methods.

I thought this was absolutely thrilling, and I hope you will find it interesting at least! :)

Follow Johan Classon:

Azure enthusiast, .Net Developer, PowerShell empowered DevOps hacker, and Solutions Architect.

One Response

  1. Viktor Gilbertsson
    | Reply

    Great information! In my opinion I would say there is only two IDE worth talking about, builtin powershell ISE or powershell studio by Sapien technologies.

    If you are using powershell ISE, there is plenty of addons to fulfill your needs. ISE steroids, ISE Scripting Geek and ISERegex are my favorites.

Leave a Reply