Backup Visual Studio Code Settings and Extension List

A PowerShell script to backup your VSCode settings and extension list to remote storage.

Visual Studio Code has “Settings Sync” built in now, but if you’d prefer to backup all your settings and a list of your extensions to some remote storage, this script will do that for you.
Simply edit the $RemotePath variable to your network share / backup drive etc., save it somewhere on the PC with VSCode installed then run the script as a Scheduled Task.

This will backup:

  • Custom code snippets
  • Keybinds
  • Settings

It will also export a list of all the extensions you have installed, and create a PowerShell file to read that list and install all the extensions in it, when you need to restore them.

$SettingsPath = "$env:APPDATA\Code\User\"
$RemotePath = "\\MYSERVER\Backups\VSCode"
$ExtensionListFile = "vs_code_extensions_list.txt"
$ReinstallFile = "InstallVSCodeExtensions.ps1"


code --list-extensions > "$RemotePath\$ExtensionListFile"

Copy-Item -Path "$SettingsPath\*" -Destination $RemotePath -Recurse -Force -Exclude @("workspaceStorage", "globalStorage")

if(-Not (Test-Path("$RemotePath\$ReinstallFile"))) {
    $FileContents = '$RemotePath = "'+ $RemotePath +'"
$ExtensionList = "' + $ExtensionListFile + '"

foreach($line in Get-Content "$RemotePath\$ExtensionList") {
    code --install-extension $line
}'
    New-Item -Path "$RemotePath\$ReinstallFile" -ItemType "File" -Value $FileContents
}

Leave a Reply

Your email address will not be published.