Created
October 14, 2023 09:30
-
-
Save sassdawe/60ef1666667f742f97cbff17057e2fb3 to your computer and use it in GitHub Desktop.
Mandatory user provided parameter in PowerShell
This file contains hidden or 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
function mandatoryUserBoolParam { | |
param( | |
[Parameter(Mandatory=$true)] | |
[ValidateSet("true","false","1","0","yes","no","y","n")] | |
[string]$param | |
) | |
$boolParam = $false | |
switch ($param.ToLower()) { | |
"true" { $boolParam = $true } | |
"1" { $boolParam = $true } | |
"yes" { $boolParam = $true } | |
"y" { $boolParam = $true } | |
default { $boolParam = $false } | |
} | |
$boolParam | |
} |
Jaykul
commented
Oct 18, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment