Adv PowerShell error handling, debugging, and cmdlets

10
Advanced Windows PowerShell Error Handling, Debugging, “Script Cmdlets,” and More Don Jones Concentrated Technology http:// ConcentratedTech.com

description

 

Transcript of Adv PowerShell error handling, debugging, and cmdlets

Page 1: Adv PowerShell error handling, debugging, and cmdlets

Advanced Windows PowerShellError Handling, Debugging, “Script Cmdlets,” and More

Don Jones

Concentrated Technology

http://ConcentratedTech.com

Page 2: Adv PowerShell error handling, debugging, and cmdlets

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC

Page 3: Adv PowerShell error handling, debugging, and cmdlets

Agenda

• Crazy amounts of demo, very little slide• Shell transcript and samples will be

downloadable from ConcentratedTech.com by next week

• Error Handling• Debugging Techniques• “Script Cmdlets” (Advanced Functions)• Tips along the way

Page 4: Adv PowerShell error handling, debugging, and cmdlets

Errors in PowerShell

• Non-terminating errors take the behavior in $ErrorActionPreference

• Must make terminating to trap/handle• Use the –ErrorAction (-EA) parameter• Use –ErrorVariable (-EV) to capture the

error in a variable• Use Try…Catch to actually catch the error

Page 5: Adv PowerShell error handling, debugging, and cmdlets

Debugging

• Write-Debug to write trace code• Write-Verbose to write “progress” info• $DebugPreference, $VerbosePreference• -debug and –verbose for scripts• Also: PSBreakpoints

Page 6: Adv PowerShell error handling, debugging, and cmdlets

Advanced Functions

• A function that looks and works and smells like a “real” cmdlet

• Mainly just decorating function parameters and adding comment-based help

• Couple of cool tricks to support –confirm and –whatif

• Accept both pipeline and parameter input• Let’s make one

Page 7: Adv PowerShell error handling, debugging, and cmdlets

Pretty cool stuff, eh?

• Again – shell transcript/samples will be on ConcentratedTech.com by next week

Page 8: Adv PowerShell error handling, debugging, and cmdlets

Final Q&A

• Text DONJ to 50500 for contact info

• See me for add’l resources

● Books● Workshop recordings● Demo videos● Etc

• Slide decks posted to ConcentratedTech.com by next week

Page 9: Adv PowerShell error handling, debugging, and cmdlets

Your Feedback is Important

Please fill out a session evaluation form drop it off at the conference registration

desk.

Thank you!

Page 10: Adv PowerShell error handling, debugging, and cmdlets

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC