Hello Guys,
I am new to using power shell and my scenario has too many variables for me as am still relatively new. I have power shell scripts which restore databases on SQL Server 2000, 2005 and 2012 instances. Powershell scripts are generic for restoring databases on different versions of SQL Server and they work fine. My problem is if restore fails with some error, I am not able to capture that in my log.
My powershell script has sqlcmd command something like below
SQLCMD -S $ServerName -d "master" -Q "$SQL"
Now, I want to know if there is a way of capturing the error and then do different things on error or different error actions from powershell? If I use try catch, will sqlcmd return the error information back to powershell??
Any help will be great,
Thanks
Nick