Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic.  Defining functions  Internals and parameters  Returning values  Scoping values  Using functions as filters.

Similar presentations


Presentation on theme: "Basic.  Defining functions  Internals and parameters  Returning values  Scoping values  Using functions as filters."— Presentation transcript:

1 Basic

2  Defining functions  Internals and parameters  Returning values  Scoping values  Using functions as filters

3  Function Function ( ) { }

4

5 function Write-PayCheck1 ($hours, $wage, $name) { $pay = $hours * $wage write-host "Pay to the order of " $name “: “ $pay } function Write-PayCheck2 ([int] $hours, [int] $wage, [string] $name) { $pay = $hours * $wage $wline = ("Pay to the order of {0}...{1:c2}" -f $name, $pay) write-host $wline -f Red } function Write-PayCheck3() {param($hours = 40, $wage, $name) $pay = $hours * $wage write-host "Pay to the order of " $name “: “ $pay }

6 function Write-PayCheck4() { $hours = $args[0] $wage = $args[1] $name = $args[2] $pay = $hours * $wage write-host "Pay to the order of " $name “: “ $pay }

7 function Count-Objects { begin { $lineCount = 0 } process { $lineCount++ } end { Write-Host "There are " $lineCount " lines." } Get-EventLog -List | Count-Objects

8  $profile provides the location of Microsoft.PowerShell_profile.ps1  You can place your customized functions here  OR you can keep them in a.ps1 file for later use and “source” the file. Example:..\myFunctions.ps1 Dot SpaceYour File


Download ppt "Basic.  Defining functions  Internals and parameters  Returning values  Scoping values  Using functions as filters."

Similar presentations


Ads by Google