I currently running a script and where I can see the exceptions in the control panel. For example
Exception calling "ExecuteNonQuery" with "0" argument(s): "Cannot drop the table 'testtabel', because it does not exist or you do not have permission."
At line:383 char:36
+ $insertData.ExecuteNonQuery <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
This is no error in the script so the script moves on but I want to save these exception in a text file. I tried different methods like
$_ | Out-File C:\errors.txt -Append
or other log functions I had found on the Internet.
Is there just an easy way to extract these exception to a text file?
$erroris the automatic variable for errors. So if you want to export the last error it would be$error[0] | Out-File C:\errors.txt -Append