Skip to content

Instantly share code, notes, and snippets.

@goyalmohit
Created July 1, 2019 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goyalmohit/ca346954181b6fb64b2eda8c34e3a3c3 to your computer and use it in GitHub Desktop.
Save goyalmohit/ca346954181b6fb64b2eda8c34e3a3c3 to your computer and use it in GitHub Desktop.
Function Get-Sum {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[int] $Number1,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[int] $Number2
)
Begin {
Write-Verbose "Inside Begin Block: Get-Sum"
}
Process{
Write-Verbose "Inside process block: Get-Sum"
Write-Verbose "Adding both numbers: $Number1 and $Number2"
$Sum = $Number1 + $Number2
return $Sum
}
end {
Write-Verbose "In end block: Get-Sum"
}
}
# calls function without using verbose parameter
Write-host "Calling Get-Sum without using verbose parameter"
Get-Sum -Number1 10 -Number2 7
# calls function with using verbose parameter
Write-Host "Calling Get-Sum with using verbsose parameter"
Get-Sum -Number1 10 -Number2 7 -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment