Core Skills

Chapter 8 of 18

Chapter 8: Build Your Own Commands

This chapter is about functions, and functions are one of the kindest gifts PowerShell gives you. You will learn how to pack a useful task into a short command with a name you choose, so you can run it again and again without retyping the whole thing. You will see how parameters let one function handle many cases, instead of only one fixed case. You will also meet advanced functions, which add helpful safety features for work you share with others. By the end, you will be able to write small, clear helpers that make your scripts shorter, easier to read, and much easier to fix.

2 lessons 3 learning objectives

Topics at a glance: Functions, Advanced Functions.

Where this chapter fits

This chapter comes after Chapter 7: One Way to Explore Every Store in the journey, so ideas from that chapter will feel familiar here.

After this chapter comes Chapter 9: Make Scripts Decide and Repeat.

Learning objectives

By the end of this chapter, you will be able to:

  • Write a simple function with parameters
  • Explain what param does and why parameters beat hard coded values
  • Describe an advanced function and its extra features

Lessons in this chapter

Work through the lessons in order. Each lesson page has explanations, examples, common mistakes, and a knowledge check.

  1. Lesson 1: Functions

    A function is a named block of code. You define it once, then call it by name, with values passed in as parameters.

    3 things to learn in this lesson

  2. Lesson 2: Advanced Functions

    An advanced function looks and feels like a built in cmdlet, with validation, common parameters, pipeline support, and safety checks.

    3 things to learn in this lesson