How to stop truncating of data when outputting XML from ReportServer using data returned from a stored procedure with Powershell (large XML file)

StackOverflow https://stackoverflow.com/questions/20673814

Question

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.

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.

The code is fairly simple at this point, and I am using a simplified report called "ChartReport":

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

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:

Column1


<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsof...

I have attempted to use some of the ideas already posted on SO, such as:

> $somefile Powershell 2: Easy way to direct every bit of output to a file?

out-file and specifying width Powershell Add-Content Truncating Output

Using the format-table with -autosize and -wrap

Each of these fail at some point (though the format-table method gets pretty far before it truncates).

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.

Would iterating over some sort of line break and writing each line of the object to a file be the idiomatic answer?

Was it helpful?

Solution

Use -MaxCharLength parameter of Invoke-SQLCMD command. By default it 4000.

See Invoke-SqlCmd doesn't return long string?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top