问题描述
我有一个 PowerShell 脚本,它运行一个返回 XML 的存储过程.然后我将 XML 导出到一个文件中,但是当我打开文件时,每行末尾都有 3 个点,并且该行不完整.这是使用 out-file
.
I have a PowerShell script that runs a stored procedure which returns XML. I then export the XML into a file but when I open the file, each line has 3 dots at the end and the line isn't complete. This is with using out-file
.
当我使用 Export-Clixml
时,查询返回的 XML 被转储到名为 的标签中,该标签不是我的标签之一.
When I use Export-Clixml
the XML that is returned from the query is dumped in a tag called <props>
which is not one of my tags.
我不确定从哪里开始以原始格式保存我的 XML.
I am unsure where to go from here to save my XML in it's original format.
我使用的 PowerShell 脚本与此类似:
The PowerShell Script that I am using is similar to this:
$Date = Get-Date -format "yyyyMMdd_HHmm"
$File = "C:\Temp\MyFile"+$Date+".xml"
$Query = "exec dbo.usp_MyProc"
Invoke-Sqlcmd -Query $Query -database MyDatabase -ServerInstance MyServer | out-file $File -Encoding utf8
推荐答案
需要将数据转换成XML试试这个:
You need to convert the data into XMLTry this:
[xml]$Result = Invoke-Sqlcmd -Query $Query -database MyDatabase -ServerInstance MyServer
$Result | out-file $File -Encoding utf8
或者这个
Invoke-Sqlcmd -Query $Query -database MyDatabase -ServerInstance MyServer |ConvertTo-XML |Out-File $File -Encoding utf8
这篇关于从 PowerShell 格式化 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!