Created
May 13, 2015 09:17
-
-
Save devlead/5f584eec40d17a479f96 to your computer and use it in GitHub Desktop.
ValidateScript is very powerful to validate script / fucntion parameters, example below validate country based on rest service
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
Param( | |
[ValidateScript( | |
{ | |
$countries = ((Invoke-RestMethod -Uri https://raw.githubusercontent.com/devlead/ISO-3166-Countries-with-Regional-Codes/master/all/all.json)| % Name) | |
if ( $countries -contains $_) | |
{ | |
$true | |
} | |
else | |
{ | |
throw "Valid countries:`r`n`t$($countries -join "`r`n`t")" | |
} | |
} | |
)] | |
[string]$Country | |
) | |
"You chosed an valid country : $Country" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment