Error handling in deployment script

Jul 19, 2012 at 4:19 PM

So now that I have everything set up and working, I'm trying to mature my deployment script by checking for errors during the script and returning a non-zero exit code at the very end.  I run vsdbcmd.exe and msdeploy.exe via the cmd.exe /c technique.  I'm not sure if this has anything to do with it, but the $Error.Count is always 0 no matter what when vsdbcmd or msdeploy fail.  I've tried changing the scope to Global, Private, Local, and Script, and only Global returns 0.  The rest do not return anything.  I did find that $? works fine so I use that to check if the last command ran successfully and then add that to custom global error count variable.  It's a work around, but I'm curious as to why the $Error variable does not seem to work.  Also, I ran some unit tests and the scripts use $Error properly.