chapter two

2 Get started automating

 

This chapter covers

  • Identifying what tasks you can automate.
  • The concept phases automations.
  • Examples of how to create reusable functions.
  • How to store your functions in module.

As you saw in the last chapter, most IT departments have grown beyond the days where one person could write a script for something like creating accounts. To be a truly agile and cost-effective department, your automations need to be as well. Unfortunately, many organizations are hesitant to start automation projects because of their past experiences with their projects not meeting expectations or going way over budget. I have talked with numerous people and companies that have had bad experiences with automation projects. However, I have not once come across an automation project that failed because of the technology. In every case, it was poor processes, planning, execution, or any combination of those.

In this chapter, you will learn how to make your automation project a success by using the concepts of phases and building blocks and how that applies to PowerShell. You will see how you can take a simple script and turn it into a reusable building block you can use anywhere. You will do this by taking a simple script to clean up old log files and turn it into a building block by thinking like an automator.

2.1 What to automate

2.2 The automation process

2.2.1 Building blocks

2.2.2 Phases

2.2.3 Combining building blocks and phases

2.3 The anatomy of PowerShell automation

2.4 Cleaning up old files (your first building blocks)

2.4.1 Your first function

2.4.2 Returning data from functions

2.4.3 Testing your functions

2.4.4 Problems to avoid when adding functions to scripts

2.4.5 Brevity versus efficiency

2.4.6 Careful what you automate

2.4.7 Putting it all together

2.5 Storing functions

2.5.1 Scripts vs. Modules vs. Profiles

2.5.2 When to add functions to a module

2.5.3 Creating a script module

2.5.4 Module creation tips

2.6 Summary