Using PSEdit as PowerShell editor

I like using Visual Studio Code as my PowerShell script editor, but alternative editors exist. The built-in PowerShell ISE is usually there for you on Windows, but there’s a nice PowerShell module that you can use called PSEdit. In this blog post, I will show you how to use that as an alternative to VSCode.

What is PSEdit?

It’s a PowerShell module that you can install to edit scripts in your PowerShell terminal with the following features:

  • IntelliSense
  • Syntax Highlighting
  • Format on Save
  • Script Execution
  • Error View
  • Syntax Error View

PSEdit is created and maintained by Ironman Software open-source projects. Visit them on their GitHub page here.

Installation

You can install the module by running the following:

Install-Module psedit

Using PSEdit

Opening files

After installing the module, you can use PSEdit to edit a file by running the following:

Show-PSEditor -Path .\file.path

Or you can start PSEdit by running Show-PSEditor and using File, Open to browse your script.

In the example below, I used PSEdit to edit my Export-Registry function:

As you can see, it has color coding and looks pretty nice ๐Ÿ™‚

Editing files

When editing a file, PSEdit will use IntelliSense to autocomplete things, for example:

It will also highlight any incomplete parts or errors. In the example below, the bracket { is missing, and it highlights that in red:

It can also format your script if you have the PSScriptAnalyzer module installed (Install using Install-Module PSScriptAnalyzer followed by import-module PSScriptAnalyzer if not)

In the unformatted example below, for example:

PSEdit will change to this when using Edit, Format (CTRL-SHIFT-R):

It also has mouse support, which you can use to control the Menu. Right-Click will give you these options:

Running PowerShell code

You can execute the whole PowerShell script using Debug, Run (F5), or a selection (You can hold Shift and select multiple lines) by Debug, execution selection (F8). You can also run and exit PSEdit by using Debug, Exit and Run in Console (CTRL-SHIFT-F5)

Note: Write-Host output won’t show on the output screen. Write-Output does work

Any errors can be viewed by using View, Errors. Syntax errors can be displayed using View, Syntax Errors.

Is it better than VSCode or ISE?

It’s a lightweight alternative that is easy to use and doesn’t require any installation in Windows or MacOS other than installing the module itself. The benefit of PSEdit is that it can also run on Windows Server Core, in which you can’t use GUI apps, but you can also use it in a Linux shell if you have powershell installed on it (Which I do have installed on my Raspberry Pi ๐Ÿ™‚ )

10 thoughts on “Using PSEdit as PowerShell editor

  1. “…but you donโ€™t always have that available…”. You don’t? Since when? It’s free, it doesn’t require admin privileges, and it can be installed with xcopy. It’s only not available if you choose not to use it.

  2. After issuing ‘install-module psedit’ I received this message from PS:
    NuGet provider is required to continue
    PowerShellGet requires NuGet provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories….yada-yada-yada…
    Do I need to interact with NuGet-based repositories?
    I canceled the install until I understand what this is all about.
    Dan

  3. How do you use Autocomplete? I see the drop down of options however hit enter on the selection you want doesn’t seem to work.

  4. Nice find Harm! I can see this being handy on Servers that have internet access blocked (as they should be ๐Ÿ™‚ ). It’s like the PS version of VIM!

  5. Pingback: PowerShell is fun :) Editing PowerShell scripts in Azure Cloud Shell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.