powershell でutf8とShift_JIS(SJIS、UTF8)の文字コードを相互に変換

2024年9月15日

バッチファイル

powershell -command "Get-Content  -Encoding Shift-JIS y:/wordlst.txt | Out-File y:/word.txt  -Encoding utf8" 

powershell -command "Get-Content  -Encoding utf8 y:/wordlst.txt | Out-File y:/word.txt  -Encoding Shift-JIS  " 

pwsh -command "Get-Content  -Encoding Shift-JIS y:/wordlst.txt | Out-File y:/word.txt  -Encoding utf8NoBOM " 

バージョンが古い場合
powershell -command "Get-Content  -Encoding Default y:/wordlst.txt | Out-File y:/word.txt  -Encoding utf8" 

powershell -command "Get-Content  -Encoding utf8 y:/wordlst.txt | Out-File y:/word.txt  -Encoding Default  " 

文字列を変換する

$s = "らりるれろEncoding  "
$s2 = [System.Text.Encoding]::GetEncoding('utf-8').GetString([System.Text.Encoding]::GetEncoding('utf-8').GetBytes($s))

bat,PowerShell 

Posted by eightban