Scripting with the intention to reuse

Changing gears from storing the scripts is the ability to repurpose them, or use portions of a script in multiple areas. Functions, workflows, and modules are critical to this end. Each will be described in detail in this section of the book.

Functions, functions, functions – the fun with functions

What is a function? The help file defines it as a named block of code that performs an action. So writing a function would look like this:

Function Get-PS {get-process PowerShell}

Here, the output would be nothing until the function is called like this:

Function Get-PS {get-process PowerShell}
Get-PS

The output of this is the same as Get-Process PowerShell but it is reusable and could be called at any point in the script. ...

Get PowerCLI Essentials 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.