Scripting Blog

A place to learn about PowerShell and share stories of automation

Hey, Scripting Guy! How Can I Use Try/Catch/Finally in Windows PowerShell?

  Hey, Scripting Guy! One thing I miss in Windows PowerShell is the ability to use a Try/Catch/Finally block that I can use in C#. To me it is an elegant solution to error handling. You attempt something, catch any resulting errors, and clean up the mess you made. Are there any plans in Windows PowerShell 3.0 to introduce this kind ...

Hey, Scripting Guy! How Can I Use the Test-Path Cmdlet to Check for Resources?

  Hey, Scripting Guy! Ignoring errors or bubbling up errors to the user of a script seems a bit inefficient. I mean, wouldn’t it be better to avoid the errors in the first place? I am only a beginner when it comes to writing scripts, and maybe I just do not get it, but why can’t you just write code that does not generate ...

Hey, Scripting Guy! How Can I Use the –ErrorAction Preference Parameter?

  Hey, Scripting Guy! I enjoyed reading your blog post yesterday about using $ErrorActionPreference to control the behavior of a script. One thing I never liked about using “On Error Resume Next” from VBScript was that it seemed to be an all-or-nothing type of proposition. There are certain errors I do not need to see, ...

Hey, Scripting Guy! How Can I Use $ErrorActionPreference to Control Cmdlet Handling of Errors?

   Hey, Scripting Guy! One thing I liked about using VBScript is that I could add On Error Resume Next to the top of a script, and all my problems with the script went away. It was like magic, and I used it to fix many of my scripts. I really miss this capability in Windows PowerShell. -- MW Hello MW, Microsoft Scripting Guy Ed ...

Hey, Scripting Guy! Weekend Scripter: Fibonnaci Sequence This!

Microsoft Scripting Guy Ed Wilson here, it is warming up a bit down here in Charlotte, North Carolina in the United States, and therefore I tend to gravitate outside on weekends. At least, far enough outside to make it to my woodworking shop. Today, I was thinking about building a series of boxes. One of the golden rules in box design is the ...