SSMS truncating PowerShell output

  • When I execute the following command, I get the output truncated to 79 characters, including three dots (as an ellipsis, I suppose).

    EXEC master..xp_cmdshell 'powershell.exe "Get-ChildItem D:\Databaze\paleontologie\prilohy\verejne\g -filter g417*.* -recurse | select Fullname | out-string -width 255"'

    When I execute the core command directly in Powershell, whether the text or ISE version, it works correctly, with or without the out-string -width command.

    Get-ChildItem D:\Databaze\paleontologie\prilohy\verejne\g -filter g417*.* -recurse | select Fullname | out-string -width 255

    What does it take to get SSMS to not truncate my output strings?

  • One option would be to send the results to file. I know I'd like a better option, but it's better than nothing.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Alvin Ramard (6/3/2015)


    One option would be to send the results to file. I know I'd like a better option, but it's better than nothing.

    I'd like to keep it in memory, if possible, but thank you for the idea.

  • Interesting. A similar script behaves the same (truncated results) for me both when run from Powershell and from xp_cmdshell.

    I'm not sure how you're intending to use it, so this might not work, but you could use Format-Table -Wrap instead of Out-String. That's slower, but it at least doesn't truncate.

    Alternatively, it might be something to do with how that select Fullname is processed. When I replace select Fullname with foreach-object {$_.Fullname}, I avoid truncation.

    The Powershell force is not strong with me, so these ideas may not help much. Hopefully they do, though.

    Cheers!

  • IIRC, the old "mode" command for DOS will do it for you. See the following.

    EXEC master..xp_cmdshell 'mode con cols=255 && powershell.exe "Get-ChildItem D:\Databaze\paleontologie\prilohy\verejne\g -filter g417*.* -recurse | select Fullname | out-string -width 255"'

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Mode con works, Format-Table -wrap still truncates. Thank you both.

  • pdanes (6/3/2015)


    Mode con works, Format-Table -wrap still truncates. Thank you both.

    You bet. Thanks for the feedback.

    What I don't like about PoSh output is that it will vary the width of columns based on the data being output to try and conserve horizontal space. There are ways around that but they all seem to be overly complicated.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply