I have a head scratcher and I am unsure on how to solve this one. I am looking for an enlightened individual that would know what this is about.
Let's begin with the center piece of this interrogation, this simple piece of code.
Function New-Thingy {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline = $true)]$testing
)
# Tried playiing with encoding but it didn't do anything.
# $Encoding = [System.Text.Encoding]::Default
# [Console]::OutputEncoding = $Encoding
# [Console]::InputEncoding = $Encoding
Write-Host $testing
}
'options — test' | New-Thingy
Please note that the problem does not occurs in Powershell ISE but do in VSCODE and Powershell (by invoking the ps1 script containing this code).
From both VS code and Powershell, running the script gives the following output: options — test instead
Output should be : options — test
Using F8 on that line of code afterward produce the correct output but F5 execution always output on the wrong codepage.
Furthermore, using an expandable string instead of single quoted produce the following error message :
+ "options — test" | New-Thingy
+ ~~~~~~~~~~~~~~
The string is missing the terminator: ".
- How do I get the correct output ? I attempted changing the console output / input encoding but it changes nothing
- What is happening with the expandable string and is there any way to prevent it ?
Again, Powershell ISE do the work properly, produce the correct output and does not give any error using expandable string there.
Regular powershell console does and so does VS code.
I am continuing to seek for an answer but I must admin I am a bit lost here.