Does anyone know of a good article that describes how to "design a script" RRS feed

  • General discussion

  • I am looking for an article that describes how to design a script, not how to write a script.

    There are plenty of good articles on best practise around writing scripts that include things like commenting, formatting, use full parameter names etc.

    I am a fairly intermittent coder. Usually I am writing to automate tasks for other people to use. I write several scripts over a few weeks and then may not write another script for a year. Normally I am using Powershell.

    I normally have a good idea of who will be using the scripts, what and how they will input parameters, who will use the output and what format that output will be in.

    Simple single output scripts are easy, they have one goal and you can script from input to output.
    When I script more complex tasks with several inputs, and several outputs (maybe something like an AD user creation, folder creation, confirmation email, etc.), I tend to jump straight in from inputs and work my way to the outputs. This does work, but I can also make quite a few rewrites during the process as I have not anticipated various issues or consequences. Or the rewrites may be because I can get a little OCD and then want to rewrite the code cleaner and more economical. Basically I don't plan the script, I just write it and have to backtrack several times.

    So I am looking for a good article on how to design/plan the internal logic of a script, between the inputs and the outputs, before I start coding. This is in an attempt to make me a more efficient coder.
    I hope that makes sense.


    Saturday, August 1, 2015 5:20 AM

All replies

  • Here are some video tutorials:


    Saturday, August 1, 2015 7:47 AM
  • This TechNet wiki article

    draws attention to these concerns:

    • Am I using the right construct for this situation?
    • Am I doing too many or unnecessary operations?
    • Am I working with too many objects?
    • Am I using too many shared resources?
    • Am I using collections correctly? Put another way: am I using the right (or best) collection for the task?
    • Is the pipeline the best approach?
    • Is there another command model that may work better?
    • Am I thinking about objects properly?
    • Am I using -Filter (if available)?
    • Am I reinitializing variables unnecessarily?
    • Is the task something for which jobs or runspaces could help?
    • Are my loops designed efficiently?
    • Am I using Foreach-Object when for will work just as well?
    • Are you using begin/process/end with ForEach-Object and in your scripts?
    • Are you using advanced functions?
    • Are you doing parameter checking?
    • Are you using Strict-Mode?
    • Do I limit the number of objects I connect to remotely, such as in Active Directory?
    • Do I limit the size of resultsets retrieved over the network, using filters, Where clauses, and parameters that specify values returned?
    • Do I retrieve values once, and save in a variable if needed again later?
    • Is there a low-level solution that may be more effective? .NET? P/Invoke?
    • Are you passing large collections to the pipeline instead of storing in an object?
    • Am I testing a condition unnecessarily?

    Saturday, August 1, 2015 5:44 PM
  • That is a good article however it does not tell us "how" to design software or anything.  It telss us how to build robust PowerShell scripts.  Not really the same thing.

    Software design is a long debated subject.  It has man approaches to a solution.  I recommend getting an overview of the issues raised by the concept of "design".  In admin scripting it should not be necessary to be too formalized although knowing the issues and the potential solutions can be very helpful.


    Saturday, August 1, 2015 5:53 PM
  • Being a "wiki" article, it expects the community to provide more details for the "how" content.
    Sometimes a wiki will attract an active crowdsource of content, and sometimes it stalls out.

    In any case, I thought the list of concerns in the current version of that article was well thought out.

    Saturday, August 1, 2015 5:57 PM
  • It  is still not a related  question.  The "how to design" is not the same as "performance and optimization",  Those come after the design stage. 

    1.  Gather requirements.
    2.  Analyze requirements -  (also determine performance requirements)
    3.  Select design criteria.
    4.  Model
    5.  Design
    6.  build/debug
    7.  Iteratively test and optimize performance

    There are other patterns that can be used but "design" is a late component of the process and th performance issue is first and last.  It impacts on the design criteria and philosophy chosen but is not part of the design process.

    Basically we separate analysis, design and build components.  Performance requirements drive our choice of design criteria but the "design" part come after that.


    Saturday, August 1, 2015 6:35 PM
  • Thanks for that link.

    Will PowerShell eventually get the Java language type classes with concepts like Inheritance ?
    Sunday, August 2, 2015 9:10 PM
  • Thanks for that link.

    Will PowerShell eventually get the Java language type classes with concepts like Inheritance ?

    Why do you think it is not already there and has been since the beginning.  Have you looked at the Net Framework specification?

    Everything in PowerShell is inherited from System.Object.  Is that enough inheritance.

    PowerShell or WMF 4 and earlier had no syntax for creating classes. We could only do New-Object.  In WMF 5 we can declare a class.


    Sunday, August 2, 2015 9:29 PM
  • Thanks.  It is the support you mention in WMF 5 that I was curious about.
    Sunday, August 2, 2015 10:05 PM
  • This has some class:

    class shoe{
        Shoe([string]$newType, [String] $newColor, [float]$newSize) {


    Sunday, August 2, 2015 10:27 PM
  • Thanks for the example of the PowerShell class keyword.
    I located this article on that subject

    jrv, at what stage of your 7 item outline of a software project does object design reside?

    Monday, August 3, 2015 2:21 AM
  • I suggest that you look deeper into design methodologies.  It would depend on the type of development system you are using or have chosen but most often it I part of the modeling but extends down into the build.  Some systems may order this slightly differently.  I ten to do objects after models. In the end it all depends on what you choose as a path after the requirements have been completed.

    I have even used what can be called full iterative development where all parts are iteratively done in parallel. This can allow for building a model that can be used to refine the requirements.

    RAD systems may use many methods.


    • Edited by jrv Monday, August 3, 2015 3:23 AM
    Monday, August 3, 2015 3:17 AM