Question:
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
.
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.
I am unsure where to go from here to save my XML in it’s original format.
The PowerShell Script that I am using is similar to this:
1 2 3 4 5 6 7 |
$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 |
Answer:
You need to convert the data into XML
Try this:
1 2 3 |
[xml]$Result = Invoke-Sqlcmd -Query $Query -database MyDatabase -ServerInstance MyServer $Result | out-file $File -Encoding utf8 |
or this
1 2 |
Invoke-Sqlcmd -Query $Query -database MyDatabase -ServerInstance MyServer |ConvertTo-XML |Out-File $File -Encoding utf8 |