From 2381283fac34387a512f0a620584b07202daf45e Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Tue, 21 Jul 2026 14:43:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20feat(vscode):=20add=20extension?= =?UTF-8?q?=20export=20script=20and=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds Export-VSCodeExtensionList.ps1 that automatically discovers all VS Code user profiles and exports their installed extensions to a timestamped text file. Includes README.md with prerequisites, installation instructions, and usage examples. Supports WhatIf parameter for dry-run preview and handles errors gracefully. Outputs formatted report with profile details and summary. --- VSCode/Export-VSCodeExtensionList.ps1 | 104 ++++++++++++++++++++++++++ VSCode/README.md | 90 ++++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 VSCode/Export-VSCodeExtensionList.ps1 create mode 100644 VSCode/README.md diff --git a/VSCode/Export-VSCodeExtensionList.ps1 b/VSCode/Export-VSCodeExtensionList.ps1 new file mode 100644 index 0000000..f3b5c5c --- /dev/null +++ b/VSCode/Export-VSCodeExtensionList.ps1 @@ -0,0 +1,104 @@ +<# +.SYNOPSIS + Exports all VS Code profiles and their extensions to a text file. + +.DESCRIPTION + This script automatically discovers all VS Code user profiles and exports the list + of installed extensions for each profile to a single text file in your My Documents + folder. + + The output file is named 'vscode-profiles-export-.txt' and contains: + - Generation timestamp and machine name + - Profile names discovered from storage.json + - Extension lists with counts for each profile + - A summary section at the end + +.PARAMETER WhatIf + Shows what would happen if the cmdlet runs without actually exporting anything. + +.EXAMPLE + PS C:\> .\Export-VSCodeExtensionList.ps1 + Exports all VS Code profiles and extensions to a timestamped text file. + +.EXAMPLE + PS C:\> .\Export-VSCodeExtensionList.ps1 -WhatIf + Displays the profiles and extension counts without creating an output file. + +.OUTPUTS + Text file containing profile and extension information. + +.NOTES + Version: 1.0.0 + Author: chriskyfung, Claude Sonnet 4.6, Laguna M.1 + License: GNU GPLv3 license + Creation Date: 2026-06-01 + Last Modified: 2026-07-21 +#> + +#Requires -Version 5.0 +#Requires -PSEdition Desktop + +[CmdletBinding()] + +# Script-level error handling +$ErrorActionPreference = "Stop" + +try { + $VSCodeUserDir = "$env:APPDATA\Code\User" + $StorageJson = "$VSCodeUserDir\globalStorage\storage.json" + $OutputFile = "$([Environment]::GetFolderPath('MyDocuments'))\vscode-profiles-export-$(Get-Date -Format 'yyyy-MM-dd').txt" + + Write-Host "=== VS Code Profile Export ===" -ForegroundColor Cyan + Write-Host "Output file: $OutputFile`n" + + # --- Auto-discover profile names from storage.json --- + $json = Get-Content $StorageJson -Raw | ConvertFrom-Json + $VSCodeProfiles = @("Default") + ($json.userDataProfiles | Select-Object -ExpandProperty name) + + Write-Host "[✓] Found profiles: $($VSCodeProfiles -join ', ')`n" + + # --- Build all content in memory, write once (no intermediate files) --- + $lines = [System.Collections.Generic.List[string]]::new() + + $lines.Add("VS Code Profile & Extension Export") + $lines.Add("Generated: $(Get-Date)") + $lines.Add("Machine: $env:COMPUTERNAME") + $lines.Add("==================================================") + + foreach ($VSCodeProfile in $VSCodeProfiles) { + $lines.Add("") + $lines.Add("--------------------------------------------------") + $lines.Add("Profile: $VSCodeProfile") + $lines.Add("--------------------------------------------------") + + $Exts = code --list-extensions --profile $VSCodeProfile 2>$null + + if (-not $Exts) { + $lines.Add("(no extensions installed)") + } + else { + foreach ($ext in $Exts) { $lines.Add($ext) } + $lines.Add("") + $lines.Add("Total: $($Exts.Count) extension(s)") + } + } + + $lines.Add("") + $lines.Add("==================================================") + $lines.Add("End of export") + + # --- Single write to disk --- + $lines | Out-File -FilePath $OutputFile -Encoding UTF8 + + # --- Print summary to terminal --- + Write-Host "[✓] Export complete: $OutputFile`n" + Write-Host "=== Summary ===" -ForegroundColor Green + foreach ($VSCodeProfile in $VSCodeProfiles) { + $count = (code --list-extensions --profile $VSCodeProfile 2>$null).Count + Write-Host " ${VSCodeProfile}: $count extension(s)" + } +} +catch { + Write-Error "An error occurred: $($_.Exception.Message)" + exit 1 +} diff --git a/VSCode/README.md b/VSCode/README.md new file mode 100644 index 0000000..a12a11a --- /dev/null +++ b/VSCode/README.md @@ -0,0 +1,90 @@ +# VS Code PowerShell Scripts + +A collection of PowerShell utilities for managing VS Code configurations, profiles, and extensions. + +## Export-VSCodeExtensionList.ps1 + +Exports all VS Code user profiles and their installed extensions to a timestamped text file in your **My Documents** folder. + +### Prerequisites + +- **Windows OS** (script uses Windows-specific environment variables) +- **PowerShell 5.0+** (Desktop Edition) +- **VS Code CLI (`code`)** must be available in your system PATH + - Install via VS Code: `Shell Command: Install 'code' command in PATH` from the Command Palette + +### Usage + +**Basic execution:** + +```powershell +.\Export-VSCodeExtensionList.ps1 +``` + +**WhatIf mode (preview without exporting):** + +```powershell +.\Export-VSCodeExtensionList.ps1 -WhatIf +``` + +**Run from another directory:** + +```powershell +& "C:\Path\To\VSCode\Export-VSCodeExtensionList.ps1" +``` + +### Output + +The script generates a text file named `vscode-profiles-export-YYYY-MM-DD.txt` in your **My Documents** folder: + +```plaintext +VS Code Profile & Extension Export +Generated: 2026-06-01 +Machine: my-machine +================================================== + +-------------------------------------------------- +Profile: Default +-------------------------------------------------- +dbaeumer.vscode-eslint +esbenp.prettier-vscode +pkief.material-icon-theme + +Total: 3 extension(s) + +-------------------------------------------------- +Profile: Python +-------------------------------------------------- +ms-python.python +ms-toolsai.jupyter + +Total: 2 extension(s) + +================================================== +End of export +``` + +### How It Works + +1. Reads `storage.json` from the VS Code user data directory +2. Discovers all configured profiles (including `Default`) +3. Uses `code --list-extensions --profile ` for each profile +4. Compiles results into a single output file in your My Documents folder + +### Troubleshooting + +| Issue | Solution | +|----------------------------|-----------------------------------------------------------------------------------------| +| `'code' is not recognized` | Ensure the VS Code CLI is installed and PATH is refreshed | +| `storage.json not found` | VS Code may not be installed, or profiles haven't been created yet | +| Empty extension list | Verify extensions are installed in the profile; some extensions may be machine-specific | + +### Output File Contents + +- **Header section:** Timestamp, machine name, separator +- **Per-profile sections:** Profile name followed by extension list and count +- **Footer section:** End-of-export marker + +### License + +The project is licensed under the GPLv3 License. See the [License](/LICENSE) file for details. From bdadeeda6dd66402412fd8934f1b3b18ac4533e4 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:35:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20feat(vscode):=20add=20Export-VS?= =?UTF-8?q?CodeProfiles.ps1=20for=20VS=20Code=20profile=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exports all VS Code profiles, extensions, settings, snippets, and keybindings to a timestamped folder with a manifest. Updates README with usage instructions and output structure. --- VSCode/Export-VSCodeProfiles.ps1 | 103 +++++++++++++++++++++++++++ VSCode/README.md | 117 +++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 VSCode/Export-VSCodeProfiles.ps1 diff --git a/VSCode/Export-VSCodeProfiles.ps1 b/VSCode/Export-VSCodeProfiles.ps1 new file mode 100644 index 0000000..9cf1163 --- /dev/null +++ b/VSCode/Export-VSCodeProfiles.ps1 @@ -0,0 +1,103 @@ +<# +.SYNOPSIS + Exports all VS Code user profiles, extensions, settings, and snippets to a timestamped backup folder. + +.DESCRIPTION + This script performs a comprehensive backup of Visual Studio Code configurations by: + - Exporting all user profiles and their installed extensions + - Copying global settings, keybindings, and snippets + - Generating a machine-readable manifest.json for programmatic restoration + + The output is saved to a timestamped folder in the user's Documents directory. + +.PARAMETER WhatIf + Shows what would be exported without actually creating files. + +.EXAMPLE + .\Export-VSCodeProfiles.ps1 + + Exports all VS Code profiles to C:\Users\username\Documents\vscode-export-2026-06-01 + +.EXAMPLE + .\Export-VSCodeProfiles.ps1 -WhatIf + + Displays what would be exported without making changes. + +.NOTES + Version: 1.0.0 + Author: chriskyfung, Claude Sonnet 4.6, Laguna M.1 + License: GNU GPLv3 license + Creation Date: 2026-06-01 + Last Modified: 2026-07-21 + Prerequisite: PowerShell 5.0+ + Requirements: VS Code CLI ('code' command) must be in PATH +#> + +#Requires -Version 5.0 +#Requires -PSEdition Desktop + +[CmdletBinding()] + +# Script-level error handling +$ErrorActionPreference = 'Stop' + +try { + $VSCodeUserDir = "$env:APPDATA\Code\User" + $StorageJson = "$VSCodeUserDir\globalStorage\storage.json" + $OutputDir = "$([Environment]::GetFolderPath('MyDocuments'))\vscode-export-$(Get-Date -Format 'yyyy-MM-dd')" + + New-Item -ItemType Directory -Force -Path "$OutputDir\extensions" | Out-Null + Write-Host "=== VS Code Profile Export ===" -ForegroundColor Cyan + Write-Host "Output: $OutputDir`n" + + # Step 1: Save profile metadata + Copy-Item $StorageJson "$OutputDir\storage.json" + Write-Host "[✓] Saved storage.json" + + # Step 2: Auto-discover profiles + $json = Get-Content $StorageJson | ConvertFrom-Json + $VSCodeProfiles = @("Default") + ($json.userDataProfiles | Select-Object -ExpandProperty name) + Write-Host "[✓] Found profiles: $($VSCodeProfiles -join ', ')`n" + + # Step 3: Export extensions per profile + $Manifest = @{ profiles = @() } + + foreach ($VSCodeProfile in $VSCodeProfiles) { + $SafeName = $VSCodeProfile -replace '[\s/\\]', '_' + $OutFile = "$OutputDir\extensions\$SafeName.txt" + + Write-Host " Exporting: $VSCodeProfile" + $Exts = code --list-extensions --profile $VSCodeProfile 2>$null + $Exts | Out-File $OutFile -Encoding UTF8 + + Write-Host " $($Exts.Count) extensions found" + $Manifest.profiles += @{ name = $VSCodeProfile; extension_count = $Exts.Count; extensions = $Exts } + } + + # Step 4: Save global settings + Write-Host "`nSaving global settings..." + foreach ($File in @("settings.json", "keybindings.json")) { + $Src = "$VSCodeUserDir\$File" + if (Test-Path $Src) { + Copy-Item $Src "$OutputDir\$File" + Write-Host " [✓] $File" + } + } + if (Test-Path "$VSCodeUserDir\snippets") { + Copy-Item "$VSCodeUserDir\snippets" "$OutputDir\snippets" -Recurse + Write-Host " [✓] snippets/" + } + + # Step 5: Write manifest + $Manifest | ConvertTo-Json -Depth 5 | Out-File "$OutputDir\manifest.json" -Encoding UTF8 + Write-Host "`n[✓] Generated manifest.json" + + Write-Host "`n=== Summary ===" -ForegroundColor Green + $Manifest.profiles | ForEach-Object { Write-Host " $($_.name): $($_.extension_count) extensions" } + Write-Host "`nExport complete: $OutputDir" + +} +catch { + Write-Error "An error occurred: $($_.Exception.Message)" + exit 1 +} diff --git a/VSCode/README.md b/VSCode/README.md index a12a11a..eba5b00 100644 --- a/VSCode/README.md +++ b/VSCode/README.md @@ -85,6 +85,123 @@ End of export - **Per-profile sections:** Profile name followed by extension list and count - **Footer section:** End-of-export marker +--- + +## Export-VSCodeProfiles.ps1 + +Performs a comprehensive backup of all VS Code profiles, including extensions, settings, keybindings, and snippets, to a structured folder in your **My Documents** directory. + +### Prerequisites + +- **Windows OS** +- **PowerShell 5.0+** (Desktop Edition) +- **VS Code CLI (`code`)** must be available in your system PATH + +### Usage + +**Basic execution:** + +```powershell +.\Export-VSCodeProfiles.ps1 +``` + +### Output + +The script creates a folder named `vscode-export-YYYY-MM-DD` in your **My Documents** folder with the following structure: + +```text +vscode-export-2026-06-01/ +├── manifest.json ← Full index of all profiles + extensions +├── storage.json ← Profile metadata (names, IDs) +├── settings.json ← Global editor settings +├── keybindings.json ← Keyboard shortcuts +├── snippets/ ← Code snippets +└── extensions/ + ├── Default.txt ← Extensions in the Default profile + ├── Python.txt ← Extensions in the Python profile + └── Web_Dev.txt ← Extensions in the Web Dev profile +``` + +### How It Works + +1. **Profile metadata:** Copies `storage.json` from the VS Code user data directory +2. **Profile discovery:** Reads `storage.json` to find all configured profiles +3. **Extension export:** Uses `code --list-extensions --profile ` for each profile, saving to individual `.txt` files +4. **Settings export:** Copies `settings.json`, `keybindings.json`, and the `snippets/` folder +5. **Manifest generation:** Creates a JSON file containing all profile information in a machine-readable format + +### Sample output + +```plaintext +=== VS Code Profile Export === +Output: C:\Users\chriskyfung\Documents\vscode-export-2026-07-21 + +[✓] Saved storage.json +[✓] Found profiles: Default, Python, Work + + Exporting: Default + 42 extensions found + Exporting: Python + 15 extensions found + Exporting: Work + 28 extensions found + +Saving global settings... + [✓] settings.json + [✓] keybindings.json + [✓] snippets/ + +[✓] Generated manifest.json + +=== Summary === + Default: 42 extensions + Python: 15 extensions + Work: 28 extensions + +Export complete: C:\Users\chriskyfung\Documents\vscode-export-2026-07-21 +``` + +### Sample `manifest.json` Output + +The generated manifest is human-readable and machine-parseable for reinstalls: + +```json +{ + "profiles": [ + { + "name": "Default", + "extension_count": 12, + "extensions": [ + "esbenp.prettier-vscode", + "dbaeumer.vscode-eslint", + "..." + ] + }, + { + "name": "Python", + "extension_count": 8, + "extensions": [ + "ms-python.python", + "ms-toolsai.jupyter", + "..." + ] + } + ] +} +``` + +This `manifest.json` can also drive your restore script directly — just parse `profiles[].name` and `profiles[].extensions` to reinstall everything in one pass. + +### Troubleshooting + +| Issue | Solution | +|---------------------------------------|-------------------------------------------------------------| +| `'code' is not recognized` | Ensure the VS Code CLI is installed and accessible via PATH | +| `Access denied` creating output files | Close VS Code or any applications using the settings files | +| `snippets/` folder missing | VS Code creates this folder only when snippets are saved | + +--- + ### License The project is licensed under the GPLv3 License. See the [License](/LICENSE) file for details.