Last active
July 15, 2024 06:16
-
-
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
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
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