Skip to content

Instantly share code, notes, and snippets.

@g3rhard
Created July 12, 2017 04:56
Show Gist options
  • Save g3rhard/407879c8d2c41f680835030be5481e61 to your computer and use it in GitHub Desktop.
Save g3rhard/407879c8d2c41f680835030be5481e61 to your computer and use it in GitHub Desktop.
Конвертация вывода программы в Powershell
#Script by xaegr (https://xaegr.wordpress.com/2007/01/24/decoder/)
#usage:
# Get-Content notes.txt | ConvertTo-Encoding "windows-1251" "koi8-r" | Set-Content decoded.txt
# command | ConvertTo-Encoding cp866 windows-1251
function ConvertTo-Encoding ([string]$From, [string]$To){
Begin{
$encFrom = [System.Text.Encoding]::GetEncoding($from)
$encTo = [System.Text.Encoding]::GetEncoding($to)
}
Process{
$bytes = $encTo.GetBytes($_)
$bytes = [System.Text.Encoding]::Convert($encFrom, $encTo, $bytes)
$encTo.GetString($bytes)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment