Skip to content

Instantly share code, notes, and snippets.

@EmmanuelTsouris
Last active May 18, 2024 17:25
Show Gist options
  • Save EmmanuelTsouris/00bcaa9a3787a6451af5567f74b4e1c6 to your computer and use it in GitHub Desktop.
Save EmmanuelTsouris/00bcaa9a3787a6451af5567f74b4e1c6 to your computer and use it in GitHub Desktop.
Download and Silently Install Visual Studio Code (VSCode)
<#
.SYNOPSIS
This script installs Visual Studio Code Silently.
.DESCRIPTION
The script downloads the latest VSCode installer and performs a silent installation.
.NOTES
Run this script on a Windows Server instance.
#>
# 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,addcontextmenufiles,addcontextmenufolders,associatewithfiles,addtopath'" -NoNewWindow -Wait
# Clean up the installer file
Remove-Item -Path $installerPath -Force
@VertigoRay
Copy link

Thanks for the /mergetasks. I came up with a more robust installer tho:
https://github.com/UNT-CAS/Update-VSCode

@roysubs
Copy link

roysubs commented Apr 3, 2020

What switch enables installation in portable mode?

@EmmanuelTsouris
Copy link
Author

EmmanuelTsouris commented May 18, 2024

What switch enables installation in portable mode?

https://code.visualstudio.com/docs/editor/portable

Maybe something like (untested)

# Define the URL for the VSCode portable zip file
$zipUrl = "https://update.code.visualstudio.com/latest/win32-x64-archive/stable"

# Define the path to save the zip file and the installation directory
$zipPath = "$env:TEMP\vscode_portable.zip"
$installDir = "C:\VSCodePortable"

# Download the VSCode portable zip file
Write-Output "Downloading Visual Studio Code portable..."
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath

# Create the installation directory if it doesn't exist
if (-not (Test-Path $installDir)) {
    New-Item -ItemType Directory -Path $installDir
}

# Extract the zip file to the installation directory
Write-Output "Extracting Visual Studio Code portable..."
Expand-Archive -Path $zipPath -DestinationPath $installDir -Force

# Create the data folder to enable portable mode
$dataDir = "$installDir\data"
if (-not (Test-Path $dataDir)) {
    New-Item -ItemType Directory -Path $dataDir
}

# Uncomment to Clean up the zip file
# Remove-Item -Path $zipPath -Force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment