Error Handling

An Introduction to Error Handling in PowerShell - Keith Babinec's Development Blog - Site Home - MSDN Blogs
How to Use PowerShell to Write to Event Logs - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs

Use Weekend Scripter: Using Try, Catch, Finally Blocks for PowerShell Error Handling - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs to explain $Error[0] | Format-List * -Force from the PowerShell console. If you run your script via the PowerShell console and then use the above command it will list all the details of the last exception in the error stack. Change the 0 to a 1 or two and you can go further back. Very handy for finding the type to put in your try...catch construct.

It is also well worth reading PowerShell: Everything you wanted to know about exceptions which explains everything you need to know.