How to fix PowerShell not being found in Visual Studio on Mac

Getting PowerShell to run on a Mac is quite easy these days. Still you might run into issues when trying to use PowerShell not only in the default Terminal app but instead in a tool such as Visual Studio Code. This article shows how to fix an issue that causes Visual Studio Code showing error Unable to find PowerShell.

As a product manager you should always try to keep your tools clean and simple for everyone. Our documentation constantly gets updated and therefore sometimes images get obsolete. Unfortunately they are not being deleted automatically. Therefore I was looking for a way to clean up a documentation project by removing all unused image files. I found a PowerShell script for this use case but could not run it because the following error message appeared when opening the script in Visual Studio code:

Prerequisites

  1. I had installed PowerShell following this manual.
  2. Afterwards I had installed the official PowerShell extension for Visual Studio Code.
  3. Then I opened the .ps1 file in the Visual Studio Code.
  4. This caused the following error message to pop-up:
    • Unable to find PowerShell! Do you have it installed? You can also configure custom installations with the ‚powershell.powerShellAdditionalExePaths‘ settings.

The issue was clear: Visual Studio code was using a built-in variable to determine where PowerShell is installed on Mac but for some reason it could not be found. Therefore I had to set the path manually.

Find PowerShell installation Path

To solve this we first need to get the path where PowerShell is installed on the machine.

  1. Open Terminal.
  2. Enter whereis pwsh
  3. This will show you the exact path where the current PowerShell version is installed (in my case there was also a virtual path created that should always target to the current powershell version /opt/homebrew/bin/pwsh).

Set PowerShell installation path in Visual Studio Code Settings

Next we need to go to Visual Studio Code settings.

  1. Click Code
  2. Click Settings…
  3. Click Settings [,]
  1. Afterwards in the settings bar enter the name of the setting that was shown in the initial error message powershell.powerShellAdditionalExePaths (see image below number). Then a menu will show where you can define the two properties Item and Value.
  2. For Item you can define any value e.g. Shell
  3. For Value you need to define the path where PowerShell has been installed for you (see steps above, in my case /opt/homebrew/bin/pwsh).
  4. Finally click Add Item.

Now the only thing you need to do is restart Visual Studio Code and afterwards everything should be working fine. To check if everything is working you can create an empty .ps1 file and open it in Visual Studio Code. The PowerShell Extension Terminal should automatically open in this case (see image below).