O'Reilly logo

Microsoft Exchange 2010 PowerShell Cookbook by Mike Pfeiffer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating PowerShell functions

Functions are used to combine a series of commands into a reusable block of code that can be called using a single command. Functions can make a configuration change or return one or more objects that can either be displayed in the console or exported to an external file. You can assign the output of functions to a variable, or pipe a function to another cmdlet. In this recipe, you'll learn how to create a PowerShell function.

How to do it...

To create a function, you need to use the function keyword, followed by the name of the function, and then the function code enclosed within curly braces {}. For example, this very basic function displays three properties of a mailbox in list format:

function Get-MailboxList { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required