Introduction

Completed

Scripts often reuse the same code — within a single script or across many. Rather than repeating that code, you can create a function that you define once and reuse as needed. If you need the same function across multiple scripts, you can store it in a module that any script can share. In this module, you'll learn to create functions and modules.

Learning objectives

After completing this module, you'll be able to:

  • Describe functions.
  • Describe the implications of variable scope.
  • Explain how to create a module.
  • Explain how to use dot sourcing.

Prerequisites

Familiarity with:

  • Windows networking technologies and implementation
  • Windows Server administration, maintenance, and troubleshooting
  • Windows PowerShell and its commands to perform specific tasks
  • PowerShell cmdlets used for system administration tasks related to Active Directory, network configuration, server administration, and Windows client device administration (Windows 10 and Windows 11)
  • Windows PowerShell pipeline, PowerShell providers, and PowerShell drives
  • CIM and WMI technologies
  • The use of variables, arrays, and hash tables in Windows PowerShell