Skip to content

Instantly share code, notes, and snippets.

@dfinke
Last active July 15, 2024 06:16
Show Gist options
  • Save dfinke/6e14ff1fa95c91ab2f5748ce903c327b to your computer and use it in GitHub Desktop.
Save dfinke/6e14ff1fa95c91ab2f5748ce903c327b to your computer and use it in GitHub Desktop.
Needs to use `ConvertFrom-Json` the challenge is the settings.json file can have comments `\\` and they fail to parse
function Update-CodePSExePath {
$version=$PSVersionTable.PSVersion.Major
if($version -eq 5) {
$powerShellExePath = (get-command powershell.exe).Source
} else {
$powerShellExePath = (get-command pwsh.exe).Source
}
$settingsFile = "$env:APPDATA\Code\User\settings.json"
$LineNumber = (Select-String 'powershell.powerShellExePath' $settingsFile).LineNumber
$fileContent = Get-Content $settingsFile
$fileContent[$LineNumber-1] = "`t" + '"powershell.powerShellExePath": "{0}",' -f ($powerShellExePath.Replace("\","\\"))
$fileContent | Set-Content $settingsFile -Encoding Ascii
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment