Chapter 19. Handling Errors

After completing this chapter, you will be able to:

  • Handle missing parameters in scripts.

  • Limit the choices available to users of your scripts.

  • Handle missing rights and permissions in scripts.

  • Handle missing WMI providers in scripts.

  • Use Try...Catch...Finally to catch single and multiple errors in scripts.

When it comes to handling run-time errors in your script, you need to have an understanding of the intended use of the script. For example, just because a script runs once does not mean it will run a second time. Disks fail, networks fail, computers fail, and things are constantly in flux. The way that a script will be used is sometimes called the use-case scenario, and it describes how the user will interact with the ...

Get Windows PowerShell™ 3.0 Step by Step now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.