Chapter 5. Working with Functions

The concept of a function in many programming languages, PowerShell included, has much in common with the mathematics concept of a function. A function is an operation that accepts a set of parameters and returns new values. Mathematics requires that a function depend on its parameters only; that is, it should always return the same value given the same parameters. However, shell users do not have to comply with that restriction. A function in PowerShell is just another name for a subroutine or a piece of code that can accept parameters, execute actions, and return values.

Subroutines are possibly the most important invention in computer science and the field of programming. Invented back in 1948 by David Wheeler, ...

Get Pro Windows PowerShell 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.