1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShell 文字コード

1
Posted at

デフォルト確認(ファイル出力 $OutputEncoding)

デフォルトの出力は日本語環境だと sjis になっている
でも -Encoding Default 指定しないと違う utf16 になってしまう。。。

$OutputEncoding

BodyName          : iso-2022-jp
EncodingName      : 日本語 (シフト JIS)
HeaderName        : iso-2022-jp
WebName           : shift_jis
WindowsCodePage   : 932
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 932

ファイル読み込み -> 書き込み

結果としてはファイル読み込み、書き込み時にそれぞれ適切なエンコーディングを指定する必要がありそう。
読み込みは処理を挟まなければ問題ないけど置換とか処理したい場合はエンコーディング指定しないと思った結果にならない

# utf8 -> sjis
$read = Get-Content $filePath -Encoding UTF8;
$read | Out-File $filePath -Encoding default;

# sjis -> utf8
$read = Get-Content $filePath -Encoding default;
$read | Out-File $filePath -Encoding UTF8;

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?