As we know there are two output windows in sql server management studio like 'Results' and 'Messages',I want to capture that 'Messages' window into a log file using powershell program .For ex:- into a log file it should display like

dishantbmg (6/26/2014)Actually i wrote a powershell program which is taking an input file containing some scripts, i want to capture message window of SSMS into a log file. How can achieve that...

I could be wrong but I'm pretty sure it (code controls SSMS) can't be done automatically where you have control over what the name of the file is. You CAN do it manually just before you run your code by selecting "Results to File" instead of "Results to Grid" or "Results to Text".

An alternative might be to use the DOS redirection character for SQLCmd or pipe the output to a file when using PoSH.

--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T."--22 Aug 2013