Chapter 6. PowerShell functions

This chapter covers

  • Fundamentals of PowerShell functions
  • Function parameters and return values
  • Functions in the pipeline
  • Variable scoping

Porcupine quills. We’ve always done it with porcupine quills.

Dilbert

In this chapter we’ll begin looking at how to create reusable commands by combining the features from the previous chapters. Functions and scripts are the two command types that can be written in the PowerShell language. (Cmdlets and external commands are written in a language such as C# that can be compiled.) We’ll start with functions because they’re simpler. In the next chapter, we’ll cover scripts as well as introduce advanced programming features available to both functions and scripts.

Get Windows PowerShell in Action, Third Edition 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.