I use Visual Studio code with the Code Runner Extension to run PowerShell scripts. It works, but the output is very strange, full of unreadable characters.
German umlauts are not displayed (marked with red arrows in the following screenshot) and there are strange characters (blue arrows):
I tried to add a character set in settings.json for Code Runner with different code pages:
"code-runner.executorMap": { "powershell": "chcp 1252 & pwsh -ExecutionPolicy ByPass -File"}
But to no avail.
My script-files are all in utf8 and when I run PowerShell and the script from a terminal window, the output looks fine:
Visual Studio Code has a dedicated PowerShell extension, which avoids the problem you're facing and is generally preferable due to providing rich support for PowerShell development and debugging.
If you still want to use the Code Runner Extension, the following may help (untested):
chcp 65001
sets the active code page to65001
, i.e. UTF-8, which PowerShell then uses when emitting output.Defining the
NO_COLOR
environment variable instructs PowerShell not to use ANSI/VT escape sequences to color its for-display formatted output.It is these escape sequences that Code Runner doesn't render as such, causing the artifacts highlighted with your blue arrows.
See also: PowerShell's conceptual about_ANSI_Terminals help topic.