Skip to content

Instantly share code, notes, and snippets.

@mavaddat
Created January 15, 2023 23:56
Show Gist options
  • Save mavaddat/35236e56751e2fe8ef22663d44af238f to your computer and use it in GitHub Desktop.
Save mavaddat/35236e56751e2fe8ef22663d44af238f to your computer and use it in GitHub Desktop.
This snippet will substitute the environment variables into the VS Code settings.json file.
Get-Content -Path "$env:APPDATA\Code*\User\settings.json" | ForEach-Object -Begin { $pattern = '\$\{env:([^\}]+)\}'; } { $match = $_ | Select-String -Pattern $pattern; if ($null -ne $match) { $match = $match.Matches.Groups[1]; $match = (Get-Item -Path Env:\$match).Value -replace '\\', '\\'; $_ -replace $pattern, $match } else { $_ } } | Set-Content -Path ($temp = New-TemporaryFile) && Get-Content $temp | Set-Content -Path "$env:APPDATA\Code*\User\settings.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment