Planet PowerShell logo

Contents

How I Setup My Powershell Development Environment

In this post i will walk through the process of how i setup my PowerShell development environement on a Windows PC. This guide has been made on a Windows 11 PC, so if you are running Windows 10, you might experience that some of the application or tools, need to be installed a different way.

In this tutorial i will show how to setup the two package managers Scoop and Chocolatey, I will show you to use the package managers to install tools like: vscode, git and neovim. I will also show how to setup WSL2, Docker Desktop and neovim for editing PowerShell scripts in the Terminal.

Prerequisites

  1. Windows 11 PC
  2. Connection to the internet

Installing the Chocolatey and Scoop package Managers

I try to install as many tools and applications as possible through one of the two package managers. The reason for this, is that with the package manager you have easy access for updating your applications, and it is extremely easy compared to go out to different websites, finding the correct version, downloading and installing through a GUI.

Installing Chocolatey

For installing chocolatey it is as easy as running a simple PowerShell command.

  1. Open a PowerShell terminal as Administrator

  2. Run the following command:

1
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
  1. You now have Chocolatey installed. To verify this you can run the following command:
1
choco --version

output:

1
1.1.0

Important thing to know is that whenever you want to install a package with chocolatey you will need to open the PowerShell terminal as Administrator.

Installing Scoop

For installing Scoop it is just as simple as installing Chocolatey, and can be done with a single command

  1. Open a PowerShell terminal as Administrator

  2. Run the following command:

1
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser; Invoke-WebRequest get.scoop.sh | Invoke-Expression
  1. You now have Scoop installed. To verify this you can run the following command:
1
scoop -h

output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Usage: scoop <command> [<args>]

Some useful commands are:

alias       Manage scoop aliases
bucket      Manage Scoop buckets
cache       Show or clear the download cache
cat         Show content of specified manifest. If available, `bat` will be used to pretty-print the JSON.
checkup     Check for potential problems
cleanup     Cleanup apps by removing old versions
config      Get or set configuration values
create      Create a custom app manifest
depends     List dependencies for an app
    ...

Important to know is that if you are installing packages with scoop, you may sometimes need to use a PowerShell terminal in Administrator context, and sometimes in User context. I usually start by trying with a non-administrator PowerShell terminal.

Now you might need to add Scoop to your Environment Variable Path, before you can actualy use the package manager.

/images/how-i-setup-my-powershell-development-environment/image1.png

Updating the Windows Terminal

Depending on which build you are on, you might need to update your Windows Terminal application to a newer version, to get some newer features. In my case i needed to update the application.

Now you can either completely uninstall the application and then install it through Chocolatey by running the command:

1
choco install microsoft-windows-terminal

You can also just update the application through the Microsoft Store. You do this by opening the Store, search for “Windows Terminal” and click on “Update”.

Installing Windows Subsystem for Linux

I use Windows Subsystem for Linux quiet a bit, for developing PowerShell 7 scripts for Linux or different applications such as Python.

To install WSL2 open a PowerShell terminal as administrator and enter the command:

1
wsl --install

The installing will take a couple of minutes and once done, you will need to restart the computer.

Now as default WSL2 will install Ubuntu on you system. So once your computer has restarted you will be prompted to complete the setup of you Ubuntu instance.

To complete the ubuntu setup you will need to select a Username and Password for the user.

I always run a complete update of the Ubuntu instance with the command:

1
sudo apt update && sudp apt upgrade -y

Installing Packages

I always install the following packages:

Package Description Package Manager
VSCode IDE for writing code Chocolatey
git Source Control application Chocolatey
Docker Desktop Container runtime, and management application Chocolatey
Picpick Screenshot tool Chocolatey
Neovim Terminal text editor Scoop
Fuzzy Terminal Search tool Scoop
Curl Terminal http tool Scoop
Sudo Terminal tool for administrator elevation Scoop
Jq Terminal json parsing tool Scoop

Installing the Chocolatey Packages:

1
choco install vscode git docker-desktop picpick.portable

Installing the Scoop Packages:

1
scoop install neovim fzf curl sudo jq

Installing PowerShell 7

You can install PowerShell 7 in two different ways. You can either install it through the MSI provided by Microsoft on their website, or you can install it through Chocolatey

Installing through Chocolatey:

1
choco install powershell-core

Installing through Microsoft provided MSI:

Link to Microsoft Docs - Installing PowerShell 7

Both ways provide PowerShell 7 version 7.2.3 at the time of writing this post. But if you wanted to run with PowerShell preview you could install it through Chocolatey by running the command:

1
choco install powershell-preview

Now i would usually try out a preview version in a Docker container, and then running a stable version on my system.

Installing a Nerd Font

To be able to use oh-my-posh and Terminal-Icons in the terminal, which I will show in the next step, you will need to install a Nerd Font and set it up in Windows Terminal. The reason for this is that a Nerd Font is able to display icons in the terminal, which a regular font is not.

First you will need to download a Font, and you do this by going to Nerd Fonts downloads page and then selecting a font you like. I usually go with Hack Nerd Font.

/images/how-i-setup-my-powershell-development-environment/download-nerd-font.png

Once the fonts are downloaded, you will need to extract the content. Then in the extracted folde, select all the files. Right click and then select ‘Install’. This will install the font to your system.

All you need to do now is to select the font as default in your Windows terminal. You do this by opening Settings, and under “Profiles” select “Defaults”. Then under “Additional settings” select “Appearance”, and under “Font face” you can now select the font you downloaded.

/images/how-i-setup-my-powershell-development-environment/windows-terminal-fonts.png

Setting up my PowerShell Terminal

I have my PowerShell terminal setup with some specific tools which helps me when working in git repositories, and with some tools for easy navigation in the terminal.

First i will need to install a tool named oh-my-posh. This tool is used for showing different information in terminal, such as which directory you are in, and status of your git repository.

To install oh-my-posh run the command:

1
scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

Then I will install the following PowerShell modules:

  • ‘Terminal-Icons’ - (used for showing icons in the terminal such as directories and files)
  • ‘Z’ - (This module is a directory navigation tool)
  • ‘PSFzf’ - (Directory Navigation and file searching tool for the terminal)
  • ‘PSReadLine’ - (Tool for providing autosuggestion and completion in the terminal based on history)

Install the modules by running the commands:

1
2
3
4
5
6
7
Install-Module Terminal-Icons -Scope CurrentUser

Install-Module Z -Scope CurrentUser

Install-Module PSFzf -Scope CurrentUser

Install-Module PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck

The last thing i will do is to configure my PowerShell profile. I only run some simple thing in the profile, such as importing modules, initializing oh-my-post and setting som aliases.

to create a PowerShell profile run the command:

1
code $profile

Then add the following to the .ps1 script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Configuring Oh-my-posh Terminal
oh-my-posh init pwsh --config "$(scoop prefix oh-my-posh)\themes\amro.omp.json" | Invoke-Expression

# Importing Terminal-Icons Module
Import-Module Terminal-Icons

# Importing Z Module
Import-Module Z

# Importing Fuzzy finder tool
Import-Module PSFzf

# Configuring Fuzzy Finder
Set-PSReadLineOption -PredictionSource History
Set-PsFzfOption -PSReadLineChordProvider 'Ctrl+f' -PSreadLineChordReverseHistory 'Ctrl+r'




# Setting Alias's
Set-Alias vim nvim
Set-Alias g git
Set-Alias grep Find-String

Save the file, and in your powershell terminal you will need to re-initialize the PowerShell profile

1
. $profile

Configuring VSCode

I have a very basic setup for my vscode. I only install a handfull of extensions and then i set some custom hotkeys, for switching between the editor and the terminal.

Installing vscode extension

For installing the extensions i have created a very simple script which runs through an array of extensions and installs them. You can edit the array as you like, and then just run the script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$extensions = @(
    "aaron-bond.better-comments",
    "ecmel.vscode-html-css",
    "esbenp.prettier-vscode",
    "HansUXdev.bootstrap5-snippets",
    "ms-azuretools.vscode-azurefunctions",
    "ms-azuretools.vscode-azureresourcegroups",
    "ms-azuretools.vscode-bicep",
    "ms-azuretools.vscode-docker",
    "ms-dotnettools.vscode-dotnet-runtime",
    "ms-python.python",
    "ms-python.vscode-pylance",
    "ms-toolsai.jupyter",
    "ms-toolsai.jupyter-keymap",
    "ms-toolsai.jupyter-renderers",
    "ms-vscode-remote.remote-wsl",
    "ms-vscode.azure-account",
    "ms-vscode.powershell",
    "PKief.material-icon-theme",
    "pspester.pester-test",
    "rangav.vscode-thunder-client",
    "redhat.vscode-yaml",
    "richie5um2.vscode-sort-json",
    "ritwickdey.LiveServer",
    "yzhang.markdown-all-in-one",
    "zhuangtongfa.material-theme"
)

function Install-VSCodeExtensions {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false, HelpMessage="Array containing all vscode extensions needed")]
        [Array]$Extensions = $extensions
    )

    foreach($extension in $Extensions) {
        try {
            code --install-extension $extension
            Write-Verbose -Message "Installing vscode extension: $($extension)"
        }
        catch {
            Write-Error "Failed installing extension: $($extension)"
        }
    }
}


Install-VSCodeExtensions -Extensions $extensions -Verbose

Configuring vscode hotkeys

To configure the hotkeys, open vscode, pres ctrl+shift+p to open the command pallet. Then search for ‘Shortcuts’ and open the ‘Preferences: Open Keyboard Shortcuts (JSON)’.

Then add the following lines between ‘[]’

1
2
{ "key": "alt+right", "command": "workbench.action.terminal.focus"},
{ "key": "alt+left", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}

These hotkeys allow you to switch between the editor and the terminal with the hotkeys: ‘alt+right’ and ‘alt+left’

Configuring Neovim

I use Neovim queit often, since i am using the terminal for pretty much everything which have to do with navigation in Windows, and often i will need to edit a single line in a script of config file. Instead of having to open a vscode editor it’s usually easier and quicker to just open til file inside Neovim.

Neovim comes pretty standard which might not be the easiest way to edit PowerShell scripts with.

First you will need to creat the init.vim config file. This file is where all the configs for the editor is located.

Create the following files:

1
2
3
New-Item -Path '~/AppData/Local/nvim' -ItemType Directory
New-Item -Path '~/AppData/Local/nvim/autoload' -ItemType Directory
New-Item -Path '~/AppData/Local/nvim/init.vim' -ItemType File

Then run the following command to install vimplug:

1
2
iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |`
    ni ~/AppData/Local/nvim-data/site/autoload/plug.vim -Force

Then open the file: init.vim in vscode and add the following settings:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
" Setting up pluggable
call plug#begin('~\AppData\Local\nvim\autoload\plugged')
Plug 'https://github.com/scrooloose/nerdtree'
Plug 'sheerun/vim-polyglot'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab

" Setting line numbering
set number


" Setting coc to automaticly install coc-powershell
let g:coc_global_extensions=[ 'coc-powershell']

" Always display NERDTree when opening nvim
autocmd VimEnter * NERDTree

Now you will need to install the different plugins for PowerShell syntax highlighting and code completion. To do this open Neovim by entering ‘vim’ in the terminal.

Then press ‘:’ and write PlugInstall

This will install all the needed plugins.

The only thing left to do is to create a new file for disabling the integrated terminal in Neovim.

open a new vim editor and write

:CocConfig

Then add the following to the file:

1
2
3
{
    "powershell.integratedConsole.showOnStartup": false
}

You should now have a working Neovim setup for editing and writing Powershell code

/images/how-i-setup-my-powershell-development-environment/nvim-powershell-setup.png

Using the different tools

In this finishing section i will just quickly walk over how to use some of the tools or how to look

The Oh-My-Posh module and the Terminal Icons Tool

/images/how-i-setup-my-powershell-development-environment/image2.png

Using the PSReadLine

The configs for the PSReadline is set to use the PowerShell command history to autosuggest possible commands:

/images/how-i-setup-my-powershell-development-environment/image3.png

Using the Module Z

The Module Z is a quick directory Navigation tool.

Use the following command to see possible directoris:

1
z -l

/images/how-i-setup-my-powershell-development-environment/image4.png

The go to a directory by adding a word from one of the directories after a ‘z’:

1
z working

/images/how-i-setup-my-powershell-development-environment/image5.png

Using Fuzzy Finder

Use ‘Ctrl+r’ to navigate through your powershell history. If you type something the list will narrow to the specific text.

/images/how-i-setup-my-powershell-development-environment/image6.png

Use ‘Ctrl+f’ to search through your current directory

/images/how-i-setup-my-powershell-development-environment/image7.png