locked
Problem with setting -encoding for sc (set-content) RRS feed

  • Question

  • When I use set-content (sc) from withing a powershell script, I cannot set the encoding, I get an error that -encoding is not a valid parameter. If I run sc from the powershell command line, no problem. I need this file to be ascii, not unicode.

    code snippet:

    ...
    sc -encoding ascii -path $file "IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[$sp.name]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[$sp.name]`nGO`n"
    ...

    Wednesday, April 8, 2009 6:04 PM

Answers

  • PowerShell 1.0 haven't paramter -Encoding for Set-Content cmdlet. However, as mentioned in newsgroups, Out-File cmdlet has -Encoding parameter. In PowerShell V2 this parameter appears for Set-Content too.
    [тут могла быть ваша реклама] http://www.sysadmins.lv
    • Proposed as answer by Vincent Hu Thursday, April 9, 2009 2:56 AM
    • Marked as answer by Vincent Hu Friday, April 10, 2009 9:17 AM
    Wednesday, April 8, 2009 9:53 PM