How to change the idea to working Powershell automation in 5 steps
Hi Damian Garbus here and this is next post about Powershell scripts. In the last post 5 steps which help you to write your first Powershell script I wrote you how to start writing Powershell script step by step. I tell you a secret. Often for more advanced Powershell automation, I’m doing a few steps before I start writing the first line of the script. If you want to know what, sit back and read.
What I do before… my secret of writing scripts
Often, Powershell scripts aren’t an advanced application (can be but by default is not) which is designed and developed by huge teams. However, advanced Powershell automation should be designed before the idea will change to the code. Always you should write a Powershell script like a book for readers. All scripts should have a specification which explain to the new user what it does. Below I want to show you my scripting process.
Always you should write a Powershell script like a book for readers .
My 5 steps to change the idea to working Powershell automation
Think about the goal to achieve
Sometimes you will need one script but Sometimes more advanced scripts or Powershell module. In both, you should think about the basic goal to achieve. During work with Powershell, I have learned that a more productive way to write code is writing MVP version first. MVP means Minimum Valuable Product and describe the first version of the code with working basic feature. If you want to add more features in the first version, it will take you more time. I always list in notes all features but choose one or more basics points. Low priority features I develop in the next script version. It helps me faster finish the first version of the script.
Define all data needed for the script
Now, If you have defined the goal to achieve it’s time to list all the requirements you need to write your script. It will be all objects, modules, files, and systems from Powershell will get data to processing. It’s important to not forget anything.
Define input and output
When you have defined all required data for the script, you can define parameters which should be available for a user when the script is invoking. For example, if you define in point 2 that script required access to log files you should define a parameter with a path to this files. After this, you can define all the results of the Powershell script. It can be output in Powershell console, export result to file, import to a database, modify some settings and log it to file or other.
Draw base process schema
Now, it’s time to design your script. Everybody has another solution to this. I’m using coggle.it to draw schema of new scripts. This way helps me discover if I have all I need to write Powershell automation.
Start writing script
This is the best step. Now you can start writing your script based on all 4 steps above. How to do this you can read in the post How to write your first Powershell script.
Conclusion
It’s all 5 steps which help you design script before you start coding. Maybe for simple automation, these steps above are unnecessary, but for the more advanced script, it can be helpful.
Please let me know in the comments about your experience with a writing Powershell scripts.