O'Reilly logo

Windows PowerShell™ 3.0 Step by Step by Ed Wilson

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

Use of functions to provide ease of modification

It is a truism that a script is never completed. There is always something else to add to a script—a change that will improve it, or additional functionality someone requests. When a script is written as one long piece of inline code, without recourse to functions, it can be rather tedious and error prone to modify.

An example of an inline script is the InLineGetIPDemo.ps1 script, which follows. The first line of code uses the Get-WmiObject cmdlet to retrieve the instances of the Win32_NetworkAdapterConfiguration WMI class that Internet Protocol (IP) enabled. The results of this WMI query are stored in the $IP variable. This line of code is shown here:

$IP = Get-WmiObject -class Win32_NetworkAdapterConfiguration ...

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