Understand the Use of Functions

As you start creating your scripts, you will eventually get to the point where you need to break them down into smaller elements that can be called multiple times. Sometimes, it's helpful to break apart scripts just for readability, and sometimes you do it because you need to call the same routine more than once. To do this, you create a function. Think of a function as a compartmentalized script that is called just like a cmdlet.

Create Functions

Functions are very similar to script blocks in that they contain executable code. The main difference between a function and a script block is that script blocks are anonymous, which means they have to be assigned to a variable before they can be executed. Functions, ...

Get Automating Microsoft® SharePoint® 2010 Administration with Windows PowerShell® 2.0 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.