Home Forums Programming Powershell Powershell to get Results and Messages in SSMS inquiry RE: Powershell to get Results and Messages in SSMS inquiry

  • yhandz_21 - Tuesday, September 19, 2017 9:08 PM

    Is there a powershell script that will show both output Results and Messages. 

    For example:
    Select @@servername

    It should show on the powershell output
    Result - Server/InstanceName
    Messages- (1 row(s) affected

    Basic answer: No.

    Bit more detailed: The "message" tab you get in SSMS for row counts and print messages is a separate stream that is not as easily accessible in PowerShell. It can be accessed but not with one or two simply commands. You can see how you can do this in this post: here.

    In order to get the example output you have provided you would have to generate that yourself using `Write-Output`, passing in the desired output after you captured it.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton