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

  • Shawn Melton - Monday, September 25, 2017 1:51 AM

    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.

    can you help me to add that write output. I tried following the blog but isn't successful. or you can help adding error handling with the code