#
# paramsExample.ps1
#
Param(
[switch]$x,
[switch]$y,
[switch]$z
)
if ($x) {Write-Output "You called this script with -x"}
if ($y) {Write-Output "You called this script with -y"}
if ($z) {Write-Output "You called this script with -z"}
Function someFunction {
Param(
[switch]$a,
[switch]$b,
[switch]$c
)
Write-Output "(someFunction): a is: $a b is: $b c is: $c"
if ($x) {Write-Output "you also called this script with -x"}
if ($y) {Write-Output "you also called this script with -y"}
if ($z) {Write-Output "you also called this script with -z"}
}
#
#####
#
# calling our internal function with switch options
#
Write-Output "calling: `"someFunction -a`": $(someFunction -a)"
Write-Output "calling: `"someFunction -b`": $(someFunction -b)"
Write-Output "calling: `"someFunction -b:`$False`": $(someFunction -b:$false)"
Write-Output "calling: `"someFunction -c`": $(someFunction -c)"
Write-Output "calling: `"someFunction -a -b`": $(someFunction -a -b)"
Write-Output "calling: `"someFunction -c -b`": $(someFunction -c -b)"
Write-Output "calling: `"someFunction -a -b -c`": $(someFunction -a -b -c)"
#
#####
#
# Script switches can be accessed by running the script with switches, as in:
#
# ./paramsExample.ps1 -x -y -z
# ./paramsExample.ps1 -x:True -y:False -z
# ./paramsExample.ps1 -x:False -z:True
# ./paramsExample.ps1 -x
# ./paramsExample.ps1 -y -z
# [...]
#
# Experiment!
#