0

I have a powershell script that spool the result of an Stored Procedure in SQL Server into a DataTable. This DT has only one row that is an XML string:

#-----------------------
#-- XML file Creation --
#-----------------------
[String]$Step = "XML file Creation."
&{
  foreach ($row in $dt_table1.Rows){ 
  $row[0].ToString().Trim()
  } }| set-content $DestinationXMLFilePath

However, the output file generated by this creates a TXT file not in an XML format, if the line is too long it automatically put a new line to continue and this is not correct.

Is there a way to generate an XML in XML format?

1
  • "if the line is too long it automatically put a new line to continue and this is not correct." - can you show us such a line and what happens to it? Commented Apr 6, 2021 at 10:08

1 Answer 1

1

I found a solution, adding the -NonewLine parameter to the code:

#-----------------------
#-- XML file Creation --
#-----------------------
[String]$Step = "XML file Creation."
&{
  foreach ($row in $dt_table1.Rows){ 
  $row[0].ToString().Trim()
  } }| set-content $DestinationXMLFilePath -NoNewLine
Sign up to request clarification or add additional context in comments.

1 Comment

If your $dt_table1 only ever has one row anyway, you don't need a foreach loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.