Esto podría funcionar para usted, pero notar que va a agarrar cada archivo en la carpeta actual:
Get-ChildItem | Foreach-Object { $c = (Get-Content $_); `
Set-Content -Encoding UTF8 $c -Path ($_.name + "u") }
Lo mismo que el uso de alias para abreviar:
gci | %{ $c = (gc $_); sc -Encoding UTF8 $c -Path ($_.name + "u") }
Steven Murawski sugiere usando Out-File
en su lugar. Las diferencias entre ambos cmdlets son las siguientes:
Out-File
intentará formatear la entrada que recibe.
Out-File
La codificación predeterminada está basada en Unicode, mientras que Set-Content
usa el valor predeterminado del sistema.
He aquí un ejemplo suponiendo que el archivo test.txt
no existe en cualquiera de los casos:
PS> [system.string] | Out-File test.txt
PS> Get-Content test.txt
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
# test.txt encoding is Unicode-based with BOM
PS> [system.string] | Set-Content test.txt
PS> Get-Content test.txt
System.String
# test.txt encoding is "ANSI" (Windows character set)
De hecho, si usted no necesita ninguna codificación Unicode específica, que podría así hacer las siguientes condiciones para convertir un archivo de texto a Unicode:
PS> Get-Content sourceASCII.txt > targetUnicode.txt
Out-File
es un "operador de redirección con optiona l parámetros "de tipo.
Duplicado de http://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets y también ver http://stackoverflow.com/questions/76482/powershell -setting-encoding-for-get-content-pipeline –