Skip to content

about_pwsh and about_powershell.exe topics: add the need for UTF16-LE re -EncodedCommand #2708

@mklement0

Description

@mklement0

The -EncodedCommand requires a Base64-encoded string, but the topics mentioned in the title neglect to mention that the basis for the Base64 encoding can only be a UTF16-LE ("Unicode")-encoded string.

To demonstrate this:

# A sample PowerShell command to pass to the CLI.
$str = '"hi"'

# Base64-encode the string based on its UTF16-LE bytes.
$strEnc64Utf16 = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($str))

# Base64-encode the string based on its UTF8 bytes.
$strEnc64Utf8 = [Convert]::ToBase64String([Text.Encoding]::utf8.GetBytes($str))

# OK: UTF16-LE
pwsh -noprofile -EncodedCommand $strEnc64Utf16

# !! DOESN'T WORK: UTF8
pwsh -noprofile -EncodedCommand $strEnc64Utf8

Ditto for powershell.exe

Version(s) of document impacted

  • Impacts 6.1 document
  • Impacts 6.0 document
  • Impacts 5.1 document
  • Impacts 5.0 document
  • Impacts 4.0 document
  • Impacts 3.0 document

Metadata

Metadata

Assignees

Labels

Pri2Priority - Medium

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions