PowerShell Back-to-School Scripting Challenge

For many people, it is back-to-school time. This time of years always makes The Chairman nostalgic, so he has commissioned a new set of PowerShell scripting challenges. These tasks are aimed at beginner level PowerShell scripters, with a few bonuses targeted toward intermediate users. Although everyone is welcome and encouraged to try their hand.

The Challenges

You need to create simple PowerShell functions to meet the following goals. Each task should result in a separate function.

  • Given 2 lengths of a right triangle, calculate the missing length. You will need to let the user specify which sides (traditionally A,B and C) of the triangle they are specifying.
  • Calculate the area of a circle with a given diameter.
  • Calculate the volume of a sphere with a given diameter.
  • Calculate the volume of a cylinder from a given diameter and height.
  • Calculate the factorial of an integer.

Intermediate Additions

For those of you with a bit more PowerShell experience, your functions should include parameter validation and error handling. Your function should have an option to write a rich object to the pipeline. For example, the first challenge might have you write an object with properties of A, B, and C. Finally, you should be able to create a simple module with a manifest.

As with all challenges, please submit links to your work in the comments and not the code itself.

And it is OK to ask your kids for help. 😉


15 Replies to “PowerShell Back-to-School Scripting Challenge”

    • Jeffery Hicks

      I may not have been clear. Traditionally, the sides are A and B and the hypotenuse is C. If you know C and A you can calculate B. If you know A and B you can calculate C. That’s the challenge.

      • Dean

        Thanks Jeff, I was very torn on the topic of the function names!

        On one hand I knew I should be using standard verbs, on the other I wanted to make the function very easy to understand for the reader…

        • Jeffery Hicks

          One thing you can do is use a standard name, even if it feels a bit awkward. Then create an alias that is more user-friendly. This is useful when packaging functions into a module where you really want to follow naming standards.

  1. thedavecarroll

    I have been working on this solution since the challenge was presented, but wasn’t able to put a considerable chunk of effort into it at any given time.

    A few of the learning points were definitely new to me, such as ValidateRangeKind and the [double]::NaN. I knew of the [math] class, but I haven’t used it that often.

    Overall, this was another fun challenge.

    Here is my solution: https://bit.ly/2ZEhLKM

Comments are closed.