File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments