Monday, June 11, 2012

Something to Remember - PowerShell is Unicode by default

I have learned something working on a script to collect logins that I thought I would share. (Actually, I knew this, but didn't think much of it until . . .)

PowerShell is natively Unicode. When you use the ">" or ">>" convenience methods to write to a file, the file is Unicode encoded. This isn't a problem until you want to use the resulting text file in a program that only understands ASCII. I found this with SQL*PLUS. The solution is to either use the

Out-File –FilePath -ENCODING ASCII

full cmdlet rather than the ">" for each write statement or copy the file after it's produced:

Get-Content –LiteralPath | Out-File –FilePath -ENCODING ASCII

Enjoy!

No comments:

Post a Comment