One of the most questions that I saw in foruns is how to return the print messages from SQL Server using some PowerShell Function.
I created a function called Invoke-ExecuteTSQL. It is for T-SQL that does not return any data. Just to execute and return if it was OK or not, the message error (it it had) and the messages from print´s or any message with a severity of 10 or less from SQL Server.
to illustrate I created a Table called test(id int)
The the Posh script with a simple T-SQL with prints
and the output properties are :
Exitcode = True or False if it runs successfully
ErrorMessage = If not runs successfully,the error message
Message = All the print information in the T-SQL
It is on PoshCode