Functions


Functions are little subroutines of code that are intended to be self-contained. Functions have their own scope, as outlined in the previous discussion on scope. Variables declared within a function are accessible only to the function. If a function is run as part of a script, then the function can access the script's scope because the script is the parent of the function.

Functions are declared with the keyword function, given a name, and then can include whatever code you need. For example:

 function myFunction { $var = 3 $script:var = "Hello" } 

Notice that the function's code is enclosed by {curly braces}, which lets PowerShell know where the function starts and stops.



Windows PowerShell. TFM
Internet Forensics
ISBN: 982131445
EAN: 2147483647
Year: 2004
Pages: 289

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net