Below is my PowerShell script that connects to a remote SQL server and stored the result into a XML file.
$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
Ideally it should return sth clean and neat like this (Which is also the case when I open up the result in my SQL Server Management Studio):
<Text>
<Data>I am happy</Data>
</Text>
However, when I open the file, it gives me:
<Text><Data>I am happy</Data></Text>
I have tried to use Export-Clixml
, but the XML returned is surrounded by some meaningless tags called <props>
which is not one of my tags.
Can anyone help me out on this, not sure which way to go to save it in its original format.