Visual Studio Code (VSCode) is a powerful, lightweight code editor that supports various programming languages and is highly customizable. Installing VSCode on your Windows Server can enhance your development environment. In this blog post, I’ll show you how to automate the installation of VSCode using PowerShell.

Why Automate with PowerShell? Link to heading

Using PowerShell to install software ensures consistency, saves time, and can be easily integrated into larger automation workflows. Whether you’re setting up a new server or provisioning multiple machines, PowerShell can simplify the process.

PowerShell Script to Install VSCode Link to heading

Below is a PowerShell script that downloads the latest VSCode installer and performs a silent installation on a Windows Server.

<#
.SYNOPSIS
This script installs Visual Studio Code on a Windows Server.

.DESCRIPTION
The script downloads the latest VSCode installer and performs a silent installation.

.NOTES
Run this script with administrative privileges.
#>

# Define the URL for the VSCode installer
$installerUrl = "https://aka.ms/win32-x64-user-stable"

# Define the path to save the installer
$installerPath = "$env:TEMP\vscode_installer.exe"

# Download the VSCode installer
Write-Output "Downloading Visual Studio Code..."
Invoke-WebRequest -Uri $installerUrl -OutFile $installerPath

# Perform the silent installation
Write-Output "Installing Visual Studio Code..."
Start-Process -FilePath $installerPath -ArgumentList "/silent", "/mergetasks=!runcode" -NoNewWindow -Wait

# Uncomment to Clean up the installer file
# Remove-Item -Path $installerPath -Force

Step-by-Step Guide Link to heading

  1. Open PowerShell as Administrator:

    • Right-click the Start menu and select “Windows PowerShell (Admin)”.
  2. Save the Script:

    • Copy the script above and save it as install_vscode.ps1.
  3. Run the Script:

    • Navigate to the location where you saved the script.
    • Execute the script: .\install_vscode.ps1

Explanation of the Script Link to heading

  1. Define Installer URL: The script starts by defining the URL for the latest VSCode installer.

  2. Download the Installer: It then downloads the installer to the temporary directory using Invoke-WebRequest.

  3. Silent Installation: The script runs the installer with /silent and /mergetasks=!runcode arguments to ensure a silent installation and prevent VSCode from launching immediately after installation.

  4. Clean Up: Finally, the script optionally removes the installer file from the temporary directory.

Conclusion Link to heading

Installing Visual Studio Code on a Windows Server using PowerShell is a straightforward process that can be automated for efficiency and consistency. This script simplifies the setup, making it easy to integrate into your server provisioning workflows. By leveraging PowerShell, you can ensure a smooth and repeatable installation process.

Feel free to adapt and expand this script to suit your specific needs, such as adding additional configuration steps or integrating it into larger automation frameworks.


Emmanuel Tsouris is a Systems Development Manager working in the cloud, with extensive experience in cloud platforms, enterprise management, and automation. In his spare time, he enjoys hiking, biking, cooking, photography, and writing. For more insights and tips, visit emmanueltsouris.com.