Download presentation
Presentation is loading. Please wait.
1
Basic
2
Defining functions Internals and parameters Returning values Scoping values Using functions as filters
3
Function Function ( ) { }
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.