When invoking AWS CLI executable from within powershell (v5.1), special characters are not handled properly by powershell. Here is an example:
# This works: powershell is forwarding the output directly to stdout without touching it
> aws cognito-idp describe-user-pool --user-pool-id $MyPoolId
{
"UserPool": {
[...]
"EmailVerificationMessage": "Votre code de vérification est {####}."
[...]
}
}
# This doesn't work: powershell handles the command's output encoding improperly
> aws cognito-idp describe-user-pool --user-pool-id $MyPoolId | Out-Host
{
"UserPool": {
[...]
"EmailVerificationMessage": "Votre code de vÚrification est {####}."
[...]
}
}
The problem is exactly the same when you want to save the output to a variable ($foo = aws ...) or redirect it to a file (| Out-File "foo.json" or > "foo.json"). Changing the output encoding (| Out-File "foo.json" -Encoding xxx) does not solve the issue, because the parsing error is made when powershell decodes the exe output, not when it outputs it to the file. The issue is not present when doing the same thing from CMD.
We could switch to the AWS tools for powershell (which should handle encoding properly) instead of using the standard AWS CLI, but I was wondering how you would solve this issue when there is no powershell alternative.
[Console]::OutputEncoding. Decoding output to be sent to an exe is managed by$OutputEncoding. Does changing those to the correct encoding help the situation?