Files
PowerShell-PowerShell/test/powershell/engine/Basic/assets/WriteConsoleOut.ps1
T
Jordan Borean af26292a7a Add PSApplicationOutputEncoding variable (#21219)
Adds the $PSApplicationOutputEncoding variable that can be used to control the encoding PowerShell uses when reading the raw bytes to a string of an external application.
2025-10-21 05:13:30 +00:00

24 lines
437 B
PowerShell

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Value,
[Parameter(Mandatory)]
[string]
$Encoding
)
$enc = [System.Text.Encoding]::GetEncoding($Encoding)
$data = $enc.GetBytes($Value)
$outStream = [System.Console]::OpenStandardOutput()
try {
$outStream.Write($data, 0, $data.Length)
} finally {
$outStream.Dispose()
}