title: sqlcmd and/or PowerShell wrapping XML output
body: <p>I'm executing the following command:</p>
  
  <pre><code>sqlcmd -i "\\path\to\sqlfile.sql" -S "ServerName" -d "DBName" -y 0
  </code></pre>
  
  <p>Wherein <code>sqlfile.sql</code> is a handful of <code>DECLARE</code> statements for variables and then a tree of nested <code>SELECT ... FOR XML Path('...')</code> statements to ultimately generate a big XML string as output.</p>
  
  <p>In a PowerShell command prompt, I pipe the output to a file:</p>
  
  <pre><code>sqlcmd -i "\\path\to\sqlfile.sql" -S "ServerName" -d "DBName" -y 0 | Out-File C:\path\to\output.xml
  </code></pre>
  
  <p>(Or I could use <code>-o</code> on the command itself, I have no strong preference either way.)</p>
  
  <p>The goal here is to have a single XML file that can then be loaded into another downstream process.  This works well, save for one detail that currently has me stuck.  The output (to the file) is auto-wrapped at 2,033 characters.  Which means that it generates broken XML if (as in most cases) the wrapping breaks a tag:</p>
  
  <pre><code>&lt;SomeTag&gt;This is some content just to illustrate.&lt;/Som
  eTag&gt;
  </code></pre>
  
  <p>I've tried using <code>-w</code> on the <code>sqlcmd</code> arguments.  In testing that would successfully wrap at values lower than 2,033, but at any value higher than 2,033 (<code>20000</code> for example, which would be more than wide enough) that same maximum of 2,033 would remain.</p>
  
  <p>I also tried calling <code>-replace</code> before piping the output to try to remove line breaks, such as:</p>
  
  <pre><code>([the sqlcmd command above]) -replace "\r", "" | Out-File C:\path\to\output.xml
  </code></pre>
  
  <p>To include attempts on <code>\r</code>, <code>\n</code>, <code>\r\n</code>, and using back-ticks instead of back-slashes.  All to no avail.  (In testing, <code>-replace "KnownString", "TEST"</code> did successfully replace the known string with <code>TEST</code>.)</p>
  
  <p>Perhaps tunnel-vision has taken over here.  Am I missing something easier?  The goal is to have a PowerShell command-line command which executes a <code>.sql</code> file and puts valid XML (doesn't need to be pretty-printed, although that would be cool) into an <code>.xml</code> file.</p>
  
  <p>Is there something I can add/modify here which would break out of that 2,033-character width limit?  Or perhaps a more creative approach to achieve the same goal?</p>