O'Reilly logo

PowerCLI Essentials by Chris Halverson

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

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. ...

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