In the last chapter, you read about how to make your automation project a success by using the concepts of phases and building blocks and how those apply to PowerShell. In this chapter, you will see how to take a simple script and turn it into a reusable building block you can use anywhere. You will do this by creating a script to clean up old log files and turn it into a building block by thinking like an automator.
You will also learn how to store these building blocks for use across multiple automations. Whether you are writing a simple script to automate a repetitive task or working with a much more extensive script, knowing how to use a phased approach to your automation can save you a lot of time, money, and stress.
In this section, you are going to write a simple script (automation) to clean up old log files. In doing so, you will apply the concept of building blocks to your script creation.
As always, you start with your requirements gathering. You know that you need to remove old logs to keep the drive from filling up. You also understand that the logs must be retained for at least seven years, but after 30 days, they can go into cold storage.