In this blog, How to run PowerShell in visual Studio code on Ubuntu is shown.
▼1. Run PowerShell in Visual Studio Code on Ubuntu
We can run PowerShell on not only Windows OS but also Ubuntu 20.4 and MacOS 11 as below.
- Windows Server 2022 with Windows PowerShell 5.1 and PowerShell 7.2
- Windows Server 2019 with Windows PowerShell 5.1 and PowerShell 7.2
- macOS 11 with PowerShell Core 7.2
- Ubuntu 20.04 with PowerShell Core 7.2
PowerShell editing with Visual Studio Code
▼2. Prerequisites
2-1. Set up Ubuntu 20.04.2 LTS
https://releases.ubuntu.com/20.04/
2-2. Install Visual Studio Code
https://code.visualstudio.com/docs/setup/linux
sudo snap install --classic code
2-3. Install PowerShell Extension by the command
PowerShell editing with Visual Studio Code
code --install-extension ms-vscode.powershell
2-4. Install PowerShell by the command on Ubuntu 20.4
Installing PowerShell on Ubuntu
// Ubuntu 20.04
# Update the list of packages
sudo apt-get update
# Install pre-requisite packages.
sudo apt-get install -y wget apt-transport-https software-properties-common
# Download the Microsoft repository GPG keys
wget -q "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb"
# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb
# Update the list of packages after we added packages.microsoft.com
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
# Start PowerShell
pwsh
▼3. Run PowerShell in VS Code on Ubuntu
3-1. Make a directory
mkidr powershelltest
cd powershelltest
3-2. Create test.txt file
Create text.txt by Vi command etc and add abcd into this file.
3-3. Start Visual Studio
code .
3-4. Run PowerShell in Visual Studio Code
On the left side, PowerShell icon is shown. after clicking this icon, we can run PowerShell in the terminal of PowerShell. for the test, run Get-Content to show the contents of the text file “test.txt” that was created before.
>Get-Content test.txt
abcd

Get-Content (Microsoft.PowerShell.Management) – PowerShell | Microsoft Learn
▼4. Reference
- VS Code https://code.visualstudio.com/docs/setup/linux
- PowerShell Extension PowerShell editing with Visual Studio Code
- PowerShell Install Installing PowerShell on Ubuntu
- Get-Content (Microsoft.PowerShell.Management) – PowerShell | Microsoft Learn
That’s all. Have a nice day ahead !!!