For the following code
$sql = "select ..... for xml path('row')" # returns a long xml file
$x = Invoke-SqlCmd -Server xxxx $sql
$r = $x[0].ItemArray[0]
The returned $r
has a truncated xml string. How to make sure the full long string is returned?
The Invoke-Sqlcmd cmdlet runs a script containing the languages and commands supported by the SQL Server SQLCMD utility. The commands supported are Transact-SQL statements and the subset of the XQuery syntax that is supported by the database engine.
The official SqlServer module now includes a version of the Invoke-Sqlcmd cmdlet that runs in PSCore 6.2 and above. The version of the SqlServer module which contains this cmdlet is 21.1. 18095-preview and is available in the PowerShell Gallery.
That cmdlet has a default max character length, defaults to 4,000 characters (see Search for -MaxCharLength
) for XML or char data types.
Try the following:
$x = Invoke-SqlCmd -Server xxxx $sql -MaxCharLength <some large enough number>
Many times this solves the case:
$x = Invoke-SqlCmd -Server xxxx $sql -MaxCharLength <some large enough number>
However, there are some cases where it doesn't work:
You could try couple of solutions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With