Created
January 13, 2022 09:20
-
-
Save fatherjack/daa81508728681145ec1bce9991615f7 to your computer and use it in GitHub Desktop.
Some different parameter types and values for demonstration purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scrpt1 = { | |
if(!(test-connection 'localhost' -Count 1 -Quiet)){return} | |
else{0..7 | % { "'"+(get-date).AddDays($_)+"'" }} | |
} | |
$scrpt2 = { | |
if((get-date).minute % 2 -eq 0){ | |
@('Mon','Wed','Fri')} | |
else{ | |
@('Tue','Thu','Sat') | |
} | |
} | |
Register-ArgumentCompleter -CommandName MyTest -ParameterName AListOfthings -ScriptBlock $scrpt1 | |
Register-ArgumentCompleter -CommandName MyTest -ParameterName Day -ScriptBlock $scrpt2 | |
function mytest { | |
param( | |
[switch]$yes, # for when yes/no , true/false are all that is needed | |
[parameter()] | |
[validaterange(500gb,20tb)] # validate Min and Max values for param | |
[int64]$DiskSize = 16tb, # provide default for param if no value is provided | |
[datetime]$AListOfthings, | |
[string]$Day | |
) | |
cls | |
"AListOfThings values was provided by the Register-ArgumentCompleter" | |
"The $Day parameter had values like $Day available at run time based on a condition" | |
if ($yes) { | |
'You supplied the $Yes parameter' | |
} else { | |
'You did not supply the $Yes parameter' | |
} | |
"Disk size was {0}, {1:N2}GB, {2:N2}TB" -f $DiskSize, ($DiskSize/1gb), ($DiskSize / 1tB) | write-host | |
} | |
mytest -disksize (43980465111040/3) | |
mytest -disksize (43980465111040/3) -Day Wed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment