0

I am tring to get ps1 script from web, and run it on powershell with one line command.
For now on, the command looks like this :

Invoke-WebRequest -UseBasicParsing "URL of ps1 file" | Invoke-Expression

.ps1 script is saved as UTF-8 and setted Encoding option for powershell on the first line of .ps1 File like this.

On the first line of .ps1 file:

[System.Console]::InputEncoding = [System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

But it doesn't shows up as UTF-8. All text that can to be shown up as only UTF8 mode(Korean for now) shows up as ?????

Is there a way to fix it? If I need to fix the command to run, Can You tell me how to run to fix this issue?

SJang
  • 15
  • 4
  • What is the meaning of `| Invoke-Expression` ? – Theo Feb 06 '21 at 10:37
  • It tells powershell that it is a script, and tells to run it. (At lease what I understand) – SJang Feb 06 '21 at 10:55
  • See [this](https://stackoverflow.com/a/50023419/9898643) – Theo Feb 06 '21 at 10:59
  • I'll see that, anyway I am asking about Encoding, not Invoke-Expression. PLEASE help about encoding :/ – SJang Feb 06 '21 at 11:05
  • [1] Remove `| Invoke-Expression`, [2] capture the output: `$req = Invoke-WebRequest ..` and [3] look at `$req.Content` – Theo Feb 06 '21 at 13:34
  • It looks like the response's encoding is misinterpreted; either there is a way to request UTF-8 explicitly when calling `Invoke-WebRequest` (btw, it's simpler to use [`Invoke-RestMethod`](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-restmethod) here), or you must _re-encode_ the misinterpreted string locally - see [this answer](https://stackoverflow.com/a/53034595/45375). – mklement0 Feb 06 '21 at 14:52

0 Answers0