Summary

In this chapter, you examined using subroutines to facilitate code re-use within a single script. You looked at the advantages of using subroutines: making scripts easier to read, easier to change, and easier to write. You used a real-world example to look at the use of subroutines to perform logging when creating a large number of new users and assigning those users to groups. In the script example in this chapter, all the code associated with the logging operation was placed into a subroutine. This subroutine could easily be added to several of the other scripts examined in this book. The only trick would be to make sure you were consistent with the variable naming convention used in the subroutine.

Get Microsoft® Windows® Scripting Self-Paced Learning Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.