Skip to content

Commit 21a6710

Browse files
authored
Create IValidateSetValuesGenerator.ps1
1 parent 9815382 commit 21a6710

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<# planets.csv
2+
Planet,Diameter
3+
"Mercury","4879"
4+
"Venus","12104"
5+
"Earth","12756"
6+
"Mars","6805"
7+
"Jupiter","142984"
8+
"Saturn","120536"
9+
"Uranus","51118"
10+
"Neptune","49528"
11+
"Pluto","2306"
12+
#>
13+
14+
class Planet : System.Management.Automation.IValidateSetValuesGenerator
15+
{
16+
[String[]] GetValidValues()
17+
{
18+
$Global:planets = Import-CSV -Path "D:\planets.csv"
19+
return ($Global:planets).Planet
20+
}
21+
}
22+
23+
Function Get-PlanetDiameter
24+
{
25+
[CmdletBinding()]
26+
param
27+
(
28+
[Parameter(Mandatory = $false)]
29+
[ValidateSet([Planet])]
30+
[string]
31+
$Planet
32+
)
33+
34+
$Planet | Foreach-Object -Process {
35+
$targetplanet = $planets | Where-Object -Property Planet -match $_
36+
$output = "The diameter of planet {0} is {1} km" -f $targetplanet.Planet, $targetplanet.Diameter
37+
38+
Write-Output $output
39+
}
40+
}

0 commit comments

Comments
 (0)