【发布时间】:2020-08-17 18:33:58
【问题描述】:
下面是我的 PowerShell 脚本,它连接到远程 SQL 服务器并将结果存储到 XML 文件中。
$SQLResult = Invoke-Sqlcmd -inputfile $inputfile -ServerInstance $ServerInstance -Database $Database -Username $Username -Password $Password
$PropertyName = ($SQLResult | Get-Member -MemberType Property | Where {$_.Name -like "XML*"}).Name
$SQLResult.$PropertyName | Out-File -FilePath "C:\Temp\ExportFile.xml" -Force
理想情况下,它应该像这样返回干净整洁的东西(当我在 SQL Server Management Studio 中打开结果时也是如此):
<Text>
<Data>I am happy</Data>
</Text>
但是,当我打开文件时,它给了我:
<Text><Data>I am happy</Data></Text>
我曾尝试使用Export-Clixml,但返回的 XML 被一些名为 <props> 的无意义标签包围,这不是我的标签之一。
谁能帮我解决这个问题,不知道用哪种方法将其保存为原始格式。
【问题讨论】:
标签: sql xml powershell invoke-sqlcmd