Use splatting, hashtables and variables to keep your scripts clean
In the past few weeks, I have spend a lot of time working with the
Laying down some time and effort to keep your code as clean as possible will help you see errors, typos and correct them much quicker, rather then working with messy code.
Say Hello To My Little Friend:
Splatting is a method of passing a collection of parameter values to a command as unit. PowerShell associates each value in the collection with a command parameter. Splatted parameter values are stored in named splatting variables, which look like standard variables, but begin with an At symbol (@) instead of a dollar sign ($). The At symbol tells PowerShell that you are passing a collection of values, instead of a single value.
Taken from PowerShell Docs
Please don`t mind the code, just have a look at the formatting. The code is taken from a project I am currently working on, so it’s only meant as an example in this post. More about that project later
When you encounter some syntax error (and I promise you will ), you can just imagine how much time you need to spend just to trying to read through and correcting your code. When writing so much text on a single line, it will take up the entire width of your screen, or wrap to more lines in your console. Where is the fun in that?
Wow, isn’t that some clean, sexy PowerShell?
You see the difference right? So much easier to read, much quicker to identify a typo and you can find and even change some text input so much faster. No more time needed to scroll the entire width of your monitor trying to find that silly value that didn`t work out as you thought.
Until next time,