2016-09-20 2 views
2

XML을 반환하는 SQL Server에서 저장 프로 시저를 실행하는 스크립트가 있습니다. 그런 다음 PowerShell에서 XML 형식을 지정하여 읽을 수있는 기능을 제공합니다. 내가 크롬에서 XML을 열 때이 오류가 얻을 :Powershell XML 인코딩

This page contains the following errors: 

error on line 149 at column 27: Encoding error 
Below is a rendering of the page up to the first error. 

내가 UTF8에서 인코딩 할 필요가 있다고 생각을하지만 난 내 코드에서 그것을 할 경우 확실입니다. 오류를 바로 잡는 방법이나 인코딩을 수행하는 방법에 대한 도움을 주시면 감사하겠습니다. 여기

내가 XML 파일을 얻기 위해 실행 파워 쉘입니다 :

function Format-XML { 
    [CmdletBinding()] 
    Param ([Parameter(ValueFromPipeline=$true,Mandatory=$true)][string]$xmlcontent) 
    $xmldoc = New-Object -TypeName System.Xml.XmlDocument 
    $xmldoc.LoadXml($xmlcontent) 
    $sw = New-Object System.IO.StringWriter 
    $writer = New-Object System.Xml.XmlTextwriter($sw) 
    $writer.Formatting = [System.XML.Formatting]::Indented 
    $xmldoc.WriteContentTo($writer) 
    $sw.ToString() 
} 


$Date = Get-Date -format "yyyyMMdd_HHmm" 
$File = "C:\Temp\MyFile"+$Date+".xml" 

$Query = "EXEC dbo.usp_MyProc" 

$resultRow = Invoke-Sqlcmd -Query $Query -database MyDatabase -ServerInstance MyServer 


Format-xml $resultRow['results'] | Set-Content -Path $File -Force 
+5

추가 시도'-Encoding UTF8' 마지막 행까지 –

답변

0

댓글 마틴 브랜디에서 "마지막 라인에 UTF8을 -encoding 추가 시도"일