Created
January 15, 2023 23:56
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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