I've written a script to make lots of regular expression modifications to a file and overwrite the file with the changes. However I have just noticed all the files are being written with UTF-16LE encoding. I realise that I can specify the encoding for the Out-File cmdlet, but I'm not confident that all the input files are the same encoding. Can I get the encoding from Get-Content somehow, or should I be using some other method of I/O? An outline of the script is below
Get-ChildItem *.aspx -Recurse| ForEach-Object {
MakeWritable($_)
(Get-Content -raw $_) | FixUp($_.FullName)
}
Filter FixUp($filename)
{
DoReplacements($_) | Out-File $filename
}