title: How to stop truncating of data when outputting XML from ReportServer using data returned from a stored procedure with Powershell (large XML file)
body: <p>I have been twiddling with a fairly simple idea to export ReportServer reports from the underlying database and then find its dependent stored procedures and export them as well.</p>
  
  <p>However, when testing initially I found that the XML data for the report itself is truncated in the standard way I export things to files, and I think I may be using an incorrect method.</p>
  
  <p>The code is fairly simple at this point, and I am using a simplified report called "ChartReport":</p>
  
  <pre><code>Import-Module 'sqlps'
  $saveloc = "$home\savedata\filename.txt"
  
  $dataquery = @"
          DECLARE @name NVARCHAR(MAX)='ChartReport',
                  @path NVARCHAR(MAX) = '/ChartReport'
      SELECT CAST(CAST(c.Content AS VARBINARY(MAX)) AS XML) [ReportData], c.Name, c.Path
      FROM ReportServer.dbo.Catalog c
      WHERE   c.Name = @name
      AND c.Path  LIKE @path+'%'
  "@
  
  Invoke-SQLCMD -Query $dataquery | select ReportData | Out-File $saveloc
  </code></pre>
  
  <p>I have verified the query returns XML (The underlying XML file itself is over 25000 characters, and I would be happy to provide a link to it if anyone is interested), however when I save the file I get something like:</p>
  
  <p>Column1</p>
  
  <hr>
  
  <p>&lt;Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsof...</p>
  
  <p>I have attempted to use some of the ideas already posted on SO, such as:</p>
  
  <p>&gt; $somefile <a href="https://stackoverflow.com/questions/7355137/powershell-2-easy-way-to-direct-every-bit-of-output-to-a-file?rq=1">Powershell 2: Easy way to direct every bit of output to a file?</a></p>
  
  <p>out-file and specifying width <a href="https://stackoverflow.com/questions/13074942/powershell-add-content-truncating-output">Powershell Add-Content Truncating Output</a></p>
  
  <p>Using the format-table with -autosize and -wrap </p>
  
  <p>Each of these fail at some point (though the format-table method gets pretty far before it truncates).</p>
  
  <p>I would definitely consider some sort of XML specific solution, but really I think it is just that I am missing some information. As far as I am considering, this is a file of "stuff" and I want to write said file to the disk after it is loaded into the object. </p>
  
  <p>Would iterating over some sort of line break and writing each line of the object to a file be the idiomatic answer?</p>