|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 5:38 AM
Points: 344,
Visits: 601
|
|
Hi all,
I use Powershell to deploy DB scripts. In one script file, I have French accented characters. When I call Invoke-sqlcmd and pass the script to the -inputfile, the French characters get mangled.
In the bad old days, the workaround was to save the files as unicode, and sqlcmd would handle them OK. How do I go about this in this brave new world?
Thanks!
Paul
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 7:22 AM
Points: 6,693,
Visits: 11,707
|
|
Cmdlet Out-File has a -Encoding option.
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 5:38 AM
Points: 344,
Visits: 601
|
|
Forgive me, maybe it's too early on Monday, but I'm not sure how that helps me?
The source file is fine, it's getting the accents into SQL Server that's problematic.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 7:22 AM
Points: 6,693,
Visits: 11,707
|
|
Sorry I misunderstood the scenario. Try changing the input file encoding from UTF-16LE (what Microsoft calls "Unicode") to UTF-32 and see if passing that file works. It's a workaround but I think you need it for Invoke-SqlCmd to get the job done. It's an open issue with the file handling in the Cmdlet.
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 5:38 AM
Points: 344,
Visits: 601
|
|
I was able to Set-Content of the source files to Unicode, and they appeared OK when opened in SSMS. I had a test version working fine; but when those files were passed to Invoke-Sqlcmd, the accented chars were again mangled.
So I've reverted to using sqlcmd.
Thanks for taking the time to respond.
P
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 7:22 AM
Points: 6,693,
Visits: 11,707
|
|
You're welcome. Happy you got it sorted.
As I said though, "Unicode" = UTF-16LE. I was saying to try the input file in UTF-32 format. Something like this would have created it:
"Hello world!" | Out-File -FilePath C:\InputFile.txt -Encoding UTF32
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 9:49 AM
Points: 464,
Visits: 299
|
|
Using Powershell 3, I had the same problem but ended up doing this:
$UnicodeFileName = $ScriptPath + "\UnicodeFileContent.sql"
$FileContent = Get-Content $FileName
$FileContent | Out-File -FilePath $UnicodeFileName -Encoding Unicode
Invoke-Sqlcmd -ServerInstance $SqlServer -Database $Database -InputFile $UnicodeFileName -AbortOnError -Verbose
___________________________________ I love you but you're standing on my foot.
|
|
|
|